I received some feedback on my previous post on setting up MvvmCross for Xamarin.Forms, asking how to add a splash screen to the Android Forms application. In the post MVX=0 I converted the MainActivity that comes as part of the standard Xamarin Android project into a SplashScreen but when it came to the Android project for Xamarin.Forms I left it without a splash screen.
Luckily adding a splash screen is really easy, so let’s add one to the Forms.Droid project:
- Copy the SplashScreen.axml from the /Resources/layout folder in the FirstDemo.Droid project into the /Resources/layout folder in the Forms.Droid project
- Remove “MainLauncher = true” from the Activity attribute on the MainActivity
- Change the MainActivity inheritance:
public class MainActivity : MvxFormsAppCompatActivity<MainViewModel>
- Add a new class, SplashScreen.cs:
[Activity(Label = "FirstDemo.Forms.Splash", Theme = "@style/MainTheme", MainLauncher = true, NoHistory = true)]
public class SplashScreen : MvxFormsSplashScreenAppCompatActivity<MvxFormsAndroidSetup<Core.App, App>, Core.App, App>
public SplashScreen() : base(Resource.Layout.SplashScreen)
protected override void RunAppStart(Bundle bundle)
And there you have it – the Android Xamarin.Forms project will launch with a splash screen before redirecting to the MainActivity which will host the Xamarin.Forms content.