An overview of the

Android12 has added a helper class for SplashScreen’s launch page. However, it is not backward compatible and can only be used on android12. Therefore, a downward compatible jetpack version of SplashScreen has been developed in Jetpack (it is still alpha and therefore not recommended for use in the project). This article will briefly cover the use of SplashScreen for Jetpack.

Simple and easy to use

Introduction of depend on

implementation 'androidx. Core: the core - splashscreen: 1.0.0 - alpha02'

Copy the code

Configure the topic

<style name="AnananSplashScreen" parent="Theme.SplashScreen">The background of the splash screen, using windowBackground by default<item name="windowSplashScreenBackground">#d73</item>Static drawable or animated vector drawable is supported<item name="windowSplashScreenAnimatedIcon">@mipmap/ic_launcher</item># Animation icon duration, up to 1000 ms<item name="windowSplashScreenAnimationDuration">1000</item>The theme of the Activity after the launch screen exits<item name="postSplashScreenTheme">@style/Theme.SplashScreenSample</item># Set the color of the icon. In this case, the icon is opaque, so you can't see the effect<item name="windowSplashScreenIconBackgroundColor">#f00</item>
    </style>
Copy the code

Configure the Activity theme in the manifest

 <activity
            android:name=".MainActivity"
            android:theme="@style/AnananSplashScreen"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
Copy the code

Configure the SplashScreen code in the Activity

All it takes is one line of code to install the Jetpack version of SplashScreen and use it

installSplashScreen()
Copy the code

Extended display time

The setKeepVisibleCondition method extends the display time

 private fun initSplashScreen(a) {
        var startMillis = SystemClock.uptimeMillis()
        val mSplashScreenView = installSplashScreen()
        mSplashScreenView.setKeepVisibleCondition {
            SystemClock.uptimeMillis() - startMillis < 1000 * 3}}Copy the code

rendering

Attributes that

windowSplashScreenAnimatedIcon

Center icon

windowSplashScreenBackground

The background color of the entire screen

windowSplashScreenAnimationDuration

Animation duration, maximum 1s

windowSplashScreenIconBackgroundColor

Middle icon background color

Git:github.com/ananananzhu…