Implement The Splash Screen In Xamarin.Android

Introduction

In this article, I have explained the splash screen activity in Xamarin.Android. The quickest way to render and display the splash screen is to create a custom theme and apply it to an Activity that exhibits the splash screen. When the Activity is rendered, it loads the theme and applies the drawable resource to the background of the activity.

The splash screen is implemented as an Activity that displays the branded drawable, performs any initializations, and starts up any tasks. Once the app has bootstrapped, the splash screen Activity starts the main Activity and removes itself from the application back stack.

Requirements

This guide assumes that the application targets Android API level 21 or higher. The application must also have Xamarin.Android.Support.v4 and Xamarin.Android.Support.v7.AppCompat NuGet packages added to the project.

Step 1

Create the new activity like splashActivity.cs and make the MainLauncher = true.

protected override void OnCreate(Bundle savedInstanceState) {
    base.OnCreate(savedInstanceState);
    SetContentView(Resource.Layout.splash_layout);
    System.Threading.Tasks.Task splashscreen = new System.Threading.Tasks.Task(() => {
        SplashScreen();
    });
    splashscreen.Start();
}

Step 2

Create the User Interface design for splash screens like splash_layout.xml and follow the below code design.

<?xml version="1.0" encoding="UTF-8" ?>
<GridLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_gravity="center"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/colorAccent">
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_row="1"
    android:layout_marginBottom="50dp"
    android:layout_gravity="center_horizontal"
    android:text="Kedis Software Inc 1.0.0"/>
</GridLayout>

Step 3

Create the Second Activity which is the main page of your app like ManiActivity.cs and follow the Intent below,

public async void SplashScreen() {
    await System.Threading.Tasks.Task.Delay(2000);
    var intent = new Intent(this, typeof(MainActivity));
    StartActivity(intent);
    Finish();
}

Output

Summary

An Android app takes some time to start up, especially during the first time the app is run on a device (sometimes this is referred to as a cold start). The splash screen may display start up progress to the user, or it may display branding information to identify and promote the application


Similar Articles