Search code examples
xamarin.formsxamarin.androidprismsplash-screenprism.xamarin

Splash screen prism xamarin.forms


I would like to create a splash screen in my xamarin.forms application which is using the prism.autofac.forms nuget package. Basically I want to create the same splash screen for each platform. Currently my Android application looks like this

    [Activity(Label = "MyApp", Theme = "@style/MyTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
    public class MainActivity : FormsAppCompatActivity
    {
        protected override void OnCreate(Bundle bundle)
        {
            ToolbarResource = Resource.Layout.Toolbar;
            TabLayoutResource = Resource.Layout.Tabbar;

            base.OnCreate(bundle);

            Forms.Init(this, bundle);
            LoadApplication(new Application(new DroidInitializer()));
        }
    }

and the application looks like this:

[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class Application : PrismApplication
{
    public Application(IPlatformInitializer initializer) : base(initializer)
    {
        NavigationService.NavigateHomeAsync();
    }

    protected override void RegisterTypes(IContainerRegistry containerRegistry)
    {
        containerRegistry.RegisterForNavigation<NavigationPage>("Navigation");
        containerRegistry.RegisterForNavigation<MainPage>("Index");
        containerRegistry.RegisterForNavigation<HomePage>();
    }

    protected override void OnInitialized()
    {
        InitializeComponent();
    }
}

Where should I implement and show the splash screen? I want to NavigateHome when all registering are finished.


Solution

  • Splash screens should be implemented in the platform projects.

    For iOS the recommended solution is to use a storyboard for it, https://learn.microsoft.com/en-us/xamarin/ios/app-fundamentals/images-icons/launch-screens?tabs=vsmac For Android I use to create a theme for the splash screen, https://learn.microsoft.com/en-us/xamarin/android/user-interface/splash-screen

    You can make them look the same, but you have to do it on each platform.