Add Splash Screen in Xamarin.Forms cross platform app – Android

For showing splash screen in Xamarin forms Android app we will need to follow below steps

  • Add Splash Screen Logo

Keep your splash screen logo or image handy and add it to Resources/drawable folder. My image name is splash_logo.png replace this key with your image name in further code blocks.

Though above method is not recommended way because your image may be blurred or strached based on the device resolution so please follow android guidelines and create multiple images based on resolution and place it in appropriate Android drawable folder (hdpi, xhdpi, xxhdpi etc). For more detail refer Android docs.

  • Add Splash Screen drawable

Now we will add XML drawable for splash screen layout under Resources/drawable. I have named it BackgroundStyle.xml and will reference by this name in my style further. So if you are using different name then keep that in mind further and replace on appropriate place.

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:drawable="@color/launcher_background" />
  <item android:gravity="center">
    <bitmap android:src="@drawable/splash_logo" />
  </item>
</layer-list>
  • Define Styles

Because splash screen is always displayed a full screen so lets create style extending NoActionBar style. For this open Resources/values/styles.xml in your Android project

  <style name="Theme.Splash" parent="android:Theme.Holo.Light.NoActionBar.Fullscreen">        
    <item name="android:windowBackground">@drawable/backgroundstyle</item>        
    <item name="android:windowNoTitle">true</item>        
  </style>
  • Create new Splash Screen Activity and make it default

Now in the last step we will create new activity for splash screen. So just add a new activity in your Android project and name it SplashActivity and then you have to do some slight changes in its activity attributes. Final class code will be like below:

[Activity(Label = "SplashScreenExample", Theme = "@style/Theme.Splash", MainLauncher = true, NoHistory = true, Icon = "@mipmap/icon")]
    public class SplashActivity : Activity
    {
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            System.Threading.Thread.Sleep(10000); // Simulate a long loading process on app      
            StartActivity(typeof(MainActivity));
            Finish();
        }
    }

Keep in mind that you should change the activity label to your application name otherwise in some cases you might get strange results in your build. Other then this we have set MainLauncher to true and also NoHistory to true. If you will check your current MainActivity it will also have MainLauncher set to true so now you have to make it false in MainActivity.

Also take note on Theme attribute because this should match the these name given in step three. I have also added Thread.Sleep statement just to simulate and display splash screen for longer, you can update it based on your need.

Now everything is in place to you can try to run the application see that your splash screen is working perfectly fine like you wanted it.