Quick way to create Splash Screen On Android

When the applications launched the splash screen is the first screen visible to user, the startup screen of an app is called splash screen.

In this tutorial we are going to create a splash screen for our android app.

 

To begin create android project file > new >new project>start with empty activity

Use application name as splashactivity

In the androidmanifest.xml  activity having below intent filter is the splashactivity of your app.

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

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

 

Splashactivity.java

package com.example.test;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;

public class SplashActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        new Handler().postDelayed(new Runnable() {


            @Override
            public void run() {
                // This method will be executed once the timer is over
                Intent i = new Intent(SplashActivity.this, MainActivity.class);
                startActivity(i);
                finish();
            }
        }, 5000);
    }
}

 

Splashactivity.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".SplashActivity">

    <ImageView
        android:layout_width="253dp"
        android:layout_height="279dp"
        android:src="@color/colorAccent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:layout_width="252dp"
        android:layout_height="111dp"
        android:text="Welcome"
        android:textColor="#fff"
        android:textSize="55dp"
        tools:layout_editor_absoluteX="83dp"
        tools:layout_editor_absoluteY="346dp" />

</androidx.constraintlayout.widget.ConstraintLayout>

 

Now create another activity for your app which will run after your splash activity ends.

When user open app startup screen runs for hardly 2-3 seconds after that the main app appears, using above code we have successfully created the startup screen.

Now run the App and you will see Splash screen

Hits: 140

Tags: No tags

Share your thoughts