This project is an example to have a custom Launch Screen or Splash Screen to your Xamarin Forms app for Android and iOS.
To implement a splash screen, we do not need any additional componenets or nuget packages. You can check out this video tutorial to see the code in action
Create/import the splash images into the solution. Please check the following link to understand the image size requirments for different screen sizes for Android.
Create a new xml file splash_screen.xml to display image
<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<bitmap android:src="@drawable/background" android:tileMode="disabled" android:gravity="fill" />
</item>
</layer-list>
Create a new theme/style that will render the launch image. Add the following lines to your styles.xml
<style name="MyTheme.Splash" parent="Theme.AppCompat.Light">
<item name="android:windowBackground">@drawable/splash_screen</item>
<item name="android:windowNoTitle">true</item>
</style>
Create a new Activity SplashActivity.cs that will launch the splash screen using the newly added theme
[Activity(Theme = "@style/MyTheme.Splash", MainLauncher = true, NoHistory = true)]
public class SplashActivity : AppCompatActivity
{
public override void OnCreate(Bundle savedInstanceState, PersistableBundle persistentState)
{
base.OnCreate(savedInstanceState, persistentState);
}
protected override void OnResume()
{
base.OnResume();
var intent = new Intent(this, typeof(MainActivity));
if (Intent.Extras != null)
{
intent.PutExtras(Intent.Extras);
}
StartActivity(intent);
}
}
Update MainActivity.cs class and set the property MainLauncher = false
[Activity(Label = "SplashScreen", Icon = "@mipmap/icon", Theme = "@style/MainTheme", MainLauncher = false, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
All the necessary changes are done. Run the app and verify the changes.
Please refer to the video link to understand how to implement for iOS devices.
This project is open source.