package

androidx.core.splashscreen

Overview

This Splash Screen library provides compatibility support for the android.window.SplashScreen APIs down to API 21, with support of the splash screen icon from API 23.

It is composed of a compatibility theme that needs to be set as the starting theme of the activity and a programmatic API in .

To use it, the theme of the launching Activity must inherit from Theme.SplashScreen

AndroidManifest.xml:

     <manifest...>
         <application>
         <activity>
              android:name=".MainActivity"
              android:theme="@style/Theme.App.Starting"/>
      </manifest>
 
res/values/styles.xml:
 <resources>
     <style name="Theme.App" parent="...">
     ...
     </style>

    <style name="Theme.App.Starting" parent="Theme.SplashScreen">
        <item name="windowSplashScreenBackground">@color/splashScreenBackground</item>
        <item name="windowSplashScreenAnimatedIcon">@drawable/splashscreen_icon</item>
        <item name="windowSplashScreenAnimationDuration">2000</item>
        <item name="postSplashScreenTheme">@style/Theme.App</item>
 </resources>
 
MainActivity.java:
     class MainActivity : Activity {
         fun onCreate() {
             super.onCreate()
             val splashScreen = installSplashScreen()

             // Set the content view right after installing the splash screen
             setContentView(R.layout.main_activity)
         }
     }