How To Create Splash Screen In Android Studio ?

How to create Splash Screen In Android Studio

The splash screen is most commonly the first startup screen that appears when the app is opened. In other words, it is a simple static screen for a certain time that is used to display the company's logo, name, advertising material.
Typically it is detected when the app is first launched on an Android device or it may be some kind of process that is used to show the screen to the user before the app is fully loaded.

Splash Screen Example in Android Studio

Step 1: Create a new project and name it Splashscreen.

Step 2: Open res -> layout -> activity_main.xml (or) main.xml and add following code:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
 android:gravity="center"
    tools:context=".MainActivity">


    <ImageView
        android:id="@+id/logo_id"
        android:layout_width="250dp"
        android:layout_height="250dp"
        android:src="@drawable/logo" />


</RelativeLayout>

Step 3: Create a new XML file splashfile.xml for Splash screen and paste the following code in it.

<?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:gravity="center">

    <ImageView
        android:id="@+id/logo_id"
        android:layout_width="250dp"
        android:layout_height="250dp"
        android:layout_centerInParent="true"
        android:src="@drawable/logo"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/logo_id"
        android:layout_centerHorizontal="true"
        android:text="Code With ANdroid"
        android:textSize="30dp"
        android:textColor="#E6145D"/>

</RelativeLayout>

Step 4: Now open app -> java -> package -> MainActivity.java and add the below code.

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}

Step 6: Add this code in SplashActivity.java activity

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



public class SplashActivity extends Activity {

    Handler handler;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);

        handler=new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                Intent intent=new Intent(SplashActivity.this,MainActivity.class);
                startActivity(intent);
                finish();
            }
        },3000);

    }
}

Here is design of above code

Splash Screen

Splash Screen

Post a Comment

0 Comments