A custom splash screen is one way to add a little flair to your Xamarin.Forms app. Out of the box, the Android project doesn’t have a splash screen wired up for you, but there is a simple way. Certainly not the only way, but an easy method if you want full-screen art.

Essentially, we are going to set our MainActivity to use a special splash screen theme, then, when the app has loaded, we can swap the theme to the main app theme and continue.

Add some assets

First, we need to add the assets we are going use as our splashscreen. In this example we’ve got a handful of PNG files, in appropriate sizes, and we are going to add them the different screen dpi folders (drawable-hdpi, drawable-xhdpi etc.), as you would do with any visual asset.

 

splash0

 

The following sizes will get you started:

  • hdpi 480px X 800px
  • xhdpi 720px X 1280px
  • xxhdpi 960px X 1600px
  • xxxxdpi 1280px X 1920px

Set up a splashscreen theme

Open styles.xml and add a new theme:

  <style name="SplashTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowBackground">@drawable/splashscreen</item>
  </style>

Next, go to the main activity for your app, or whichever activity has MainLauncher set to true, and set the theme to “splashscreen”.

In the same activity, in the OnCreate method, add a call to base.SetTheme, just before the call to base.onCreate.

splash1

 

Finally, hit F5 and check out your new splash screen!

 

splash

Advertisements