Android Phones

How to Implement Android Splash Screen

Aditya Singh
How to Implement Android Splash Screen

This tutorial will teach you how to implement an android splash screenWe can see Android splash screens in every app, also known as the launch screen. When the app opens, it loads the screen, and some processes happen in the background.

Android Splash Screen Using Timer

1. Open android studio, go to File ⇒ New Project and fill in all the details.

2. To make a Splash Screen you have to make a new activity. Name that activity Splash_Screen.java (you can make it according to your wish). The XML file will be created automatically if you click blank new activity.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.androidhire.splashscreen">
    <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme">        <!-- Splash Screen-->
        <activity android:name=".Splash_Screen">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>        <!-- Main Activity-->
        <activity android:name=".MainActivity" />
    </application>
</manifest>

3. Go to res ⇒ layout then click on splash screen XML file. In this, you will show the logo or text you want to show on a splash screen. If you want to save any images then you have to put an image in res ⇒ drawable.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/bg_splash">
    <ImageView android:layout_width="match_parent" android:layout_height="match_parent" android:layout_centerInParent="true" android:minHeight="0dp" android:minWidth="0dp" android:src="@drawable/logo_splash" />
</RelativeLayout>

4. Add code to SplashScreen.java activity. In this, you have to specify the time you want to wait on that screen and after that on which activity you want to go.

package com.androidhire.splashscreen;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;

public class Splash_Screen extends AppCompatActivity {

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_splash__screen);
    new Handler()
      .postDelayed(
        new Runnable() {
          @Override
          public void run() {
            Intent i = new Intent(Splash_Screen.this, MainActivity.class);
            startActivity(i);
            finish();
          }
        },
        2000
      );
  }
}

5. I have added the background gradient, for that, you have to go res ⇒  drawable then make a file and make it bg_splash.xml. In place of a gradient, you can put some logo or normal text to show on the splash screen.

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
    <gradient android:angle="90" android:endColor="#9b2a58" android:startColor="#290505"> </gradient>
</shape>

In the drawable folder only you have to add the logo. Run the application on the emulator or on your device and check the application.

Go through the code to understand better how splash screens work. If you are unable to understand or want some features comment below.