Latest Post

6/recent/ticker-posts

How to Create Splash Screen in Android Studio?

How to create splash screen in Android Studio?

Step 1Create a new project and name it SplashScreen.

How to create Splash Screen in Android Studio?

Step 2: Open res => layout => activity_main.xml  and add following code: In this step we simply added a code to display layout after SplashScreen.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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=".MainActivity">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Welcome to Myapplication"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
</RelativeLayout>
How to create Splash Screen in Android Studio?

Step 3: Create a new XML file activity_splash.xml for SplashScreen and paste the following code in it.
This layout contains your app logo or other product logo that you want to show on SplashScreen.

<?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="@mipmap/ic_launcher"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/logo_id"
        android:layout_centerHorizontal="true"
        android:text="Splash Screen"
        android:textSize="30dp"
        android:textColor="#000"/>

</RelativeLayout>
How to create Splash Screen in Android Studio?

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

package com.splashsceen.myapplication;

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);


    }
}
How to create Splash Screen in Android Studio?

Step 5: For SplashScreen we will create a separate splash activity.Now create a new class in your java package and name it as SplashActivity.java.
Step 6: Add this code in SplashActivity.java activity. In this code handler is used to hold the screen for specific time and once the handler is out, our main Activity will be launched. We are going to hold the SplashScreen for three second’s. We will define the seconds in millisecond’s after Post Delayed(){} method.
3 second =3000 milliseconds.
Post Delayed method will delay the time for 3 seconds. After the delay time is complete, then your main activity will be launched.
SplashActivity.java 
package com.splashscreen.myapplication;

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);

    }
}
How to create Splash Screen in Android Studio?

Step 7: Open AndroidManifest.xml file and make your Splashactivity.java class as Launcher activity and mention the MainActivity as another activity.

AndroidManifest.xml 
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.splashscreen.myapplication">

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".SplashActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

</manifest>
How to create Splash Screen in Android Studio?
Try it and see results

Post a Comment

0 Comments