Adding Splash Screen in Android Application

In this tutorial we are going to create splash screen for an android application. We will create an activity and will set that activity as launcher activity for a small time.

Step 1: Splash Screen Layout

Create a new xml file in layout folder and following code in that.

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
android:orientation="vertical"
    android:background="@color/white"
    xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
    android:layout_height="match_parent">
<ImageView
    android:id="@+id/logo"

android:layout_gravity="center"
    android:layout_height="250dp"
    android:layout_width="250dp"

    android:src="@drawable/abc"
    />
</FrameLayout>

here i have used an image as a logo for app, you can also use any picture regarding to your project.

Step 2: Create Splash screen Activity

Now we need to create java class for our splash screen activity. Create a new java class and add the following code.

package com.example.kaushal97.busbay;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;


public class splash extends Activity {
    private static int time_out=3000;

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

        },time_out);
    }
}

Now in this class i have set the content layout to our splash screen layout xml file, and created a Handler. In handler we created a intent to start main_activity after the timeout.

Step 3: set AndroidMainfest.xml file

Open your Android mainfest.xml file and set launcher activity form mainActivity to splashScreen activity.

<activity android:name=".splash">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            >

        </activity>

Run your app.

Now you can customize the splash screen according to your choice.

About kaushal97

Android Enthusiast

Leave a Reply

Your email address will not be published. Required fields are marked *