How to Implement Splash Screen in AndroidAndroid Development
December 25, 20201 minuteuserVivek Beladiya
How to Implement Splash Screen in Android
what is a SplashScreen?

A splash screen is a screen that appears when you open an app on your mobile device. So, we can say that it is the first impression for the user. It is commonly used to show an application logo or an image associated with an application.



















Implementation

So instead of using a layout file, we'll refer to the splash screen as the background of the activity theme. first, create an XML drawable splash_background.xml inside res/drawable folder in

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@color/white" />
    
    <item
        android:drawable="@drawable/ic_icon_vector"
        android:gravity="center" />

</layer-list>
 next step, set splash_groundground.xml as the background for your splash activity in the theme. Add a new splash to your splash activity.


<!-- Splash Screen theme. -->
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
    <item name="android:windowBackground">@drawable/splash_background</item>
</style>
Add your theme to AndroidManifest.xml as your splash activity theme.

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

    <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/Theme">
        
        <activity
            android:name=".SplashActivity"
            android:theme="@style/SplashTheme">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>
Create a blank activity for SplashActivity.java without XML. This class will only redirect to MainActivity.java.

public class SplashActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        startActivity(new Intent(SplashActivity.this, MainActivity.class));
        finish();
    }
}