Android 12 SplashScreen (splash screen page) adaptation

complain (nonsense)

Google is really fed up, doing this and that, Android 12 has a new mandatory splash screen page, the effect is the same as Xiaomi’s splash screen page advertisement, except that Google’s is mandatory, and Xiaomi’s is optional. But no matter what Google does, you still have to adapt, which is uncomfortable.

topic

All apps running on Android 12 (no matter what the targetSdkVersion is) will forcibly pop up SplashScreen during cold startup (the application process is not running) and warm startup (the application process is in the background but there is no Activity, such as a Service). There is no way to disable SplashScreen in the official API. The fixed style of the splash screen is as follows.
insert image description here

adaptation

12 and below as usual, 12 and above first the system and then apply the splash screen

If it is acceptable to pop up the system splash screen and then pop up the application splash screen, then you don’t need to do anything, and this effect is the default.

Below 12 as usual, above 12 only system splash screen

First, compileSdkVersion must be set above 31, otherwise there will be no API for 12. Then add the following code to the onCreate method of SplashActivity

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
    
    
            getSplashScreen().setOnExitAnimationListener(view -> {
    
    
                //do nothing to keep splash screen
            });
        }

The principle is that if we do not register this listener, the system splash screen page will disappear by itself after the application starts drawing. But if we register this listener, the system will call back the system splash screen page to the application in the form of SplashScreenView after the application starts drawing, and it is up to the developer to decide how the system splash screen page disappears. For example, we can customize the animation to move up and down or fade out to make the system splash screen page disappear. We registered the OnExitAnimationListener, and if we do nothing, the system splash screen page will always be covered on the splash screen page until the application jumps to the main Activity. Or you can cache the advertisements such as SplashScreenView and so on, and then remove it to hide it.

Unified 12 styles for all system versions

This can use the official SplashScreen compat library, the link below has official documents, but it is still a beta version, and this is measured by itself. If you implement it by yourself, you need to change the previous splash screen image to the style of 12. This should not be difficult, the style of 12 is quite simple, and then block the splash screen of the application above 12 according to the above instructions.

System splash screen style configuration

The splash screen process of 12 can be divided into two steps.
One is to enter the market, that is, the above fixed style that pops up immediately after clicking Apply, through theme configuration.
You can set the background of the splash screen, but it can only be a color background, and you cannot set a picture.

<item name="windowSplashScreenBackground">#CCCCCC</item>

You can set the splash screen icon in the middle, which can be set as a picture, but the size and style (round or square) of the display is determined by the system, and it will be realized through Mask.

<item name="android:windowSplashScreenAnimatedIcon"></item>

You can set the logo pattern, according to Guo Lin's test, it should be a 4:1 ratio picture, otherwise it will be stretched.

<item name="android:windowSplashScreenBrandingImage"></item>

The system splash screen can be set to these three.
The other is exit, that is, the exit process after the application starts drawing. If there is no adaptation system, the splash screen will disappear directly. If the above monitoring is registered, the user will handle it by itself. At this time, the splash screen page is a normal View, and the application can be completely manipulation.

reference article

Migrate your existing splash screen implementation to Android 12 and higher
Android 12 SplashScreen API Quick Start An
in-depth look at how to use Jetpack SplashScreen to reinvent your app splash screen

Guess you like

Origin blog.csdn.net/Welcome_Word/article/details/125130571