Splash Screen in Android using Kotlin

Splash Screen is the first screen of the App when it is opened. It generally the logo of the App or some kind of loading animation.

We have made a video tutorial on it.

Access source code of this project here:

Step 1: Create your project

We will be creating the Splash Screen in XML and Kotlin.

Step 2: Add your Icon into the drawable folder

Now copy the icon into the drawable folder which you want to show in the splash screen. Don’t put any space(use underscore instead), uppercase later or any other special character as the name of the icon.

Step 3: Add dependency in build.gradle

implementation("androidx.core:core-splashscreen:1.0.0")

Step 4: Set the theme of Splash Screen in themes.xml

First add the color of the splash screen background in the colors.xml

<color name="dark_grey">#181818</color>

Now open themes.xml and add the style of the splash screen just like below.

    <style name="Theme.App.SplashScreen" parent="Theme.SplashScreen">
        <item name="windowSplashScreenBackground">@color/dark_grey</item>
        <item name="windowSplashScreenAnimatedIcon">@drawable/logo_large</item>
        <item name="postSplashScreenTheme">@style/Base.Theme.SplashScreenApp</item>
    </style>

Wanna Explore the world of Android deeper? Check out 1800+ Android Developer’s Resources with 500+ Android Open Source Apps, 900+ Libraries and more here

Step 5: Set splash screen as launcher theme in manifest.xml

android:theme="@style/Theme.App.SplashScreen"

Step 6: Set duration and install splash screen

Now open MainActivity, there write code to set the duration of the splash screen and install splash screen using the below code.

Thread.sleep(3000)
installSplashScreen()

Conclusion:

That’s all you need to set up a splash screen in latest API method. After all simple steps. Your splash screen will surely work.

Leave a Reply

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