项目要求是一个中间一个icon,底部一个label
安卓12以下:
<style name="LaunchTheme" parent="Theme.SplashScreen">
<item name="android:windowBackground">@drawable/splash_bg</item>
<item name="postSplashScreenTheme">@style/Theme.App</item>
<item name="android:windowNoTitle">true</item>
</style>
安卓12+
<style name="LaunchTheme" parent="Theme.SplashScreen">
<item name="windowSplashScreenAnimatedIcon">@drawable/logo_icon</item>
<item name="windowSplashScreenAnimationDuration">2000</item>
<item name="postSplashScreenTheme">@style/Theme.App</item>
<item name="android:windowNoTitle">true</item>
<item name="windowSplashScreenBackground">@color/splashScreenBackground</item>
<item name="android:windowSplashScreenBrandingImage">@drawable/splash_31_bg</item>
</style>
如果logo不是适配了8.0的话,需要自己写个xml包装一下,防止裁剪
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<color android:color="@color/splashScreenBackground" />
</item>
<item>
<bitmap
android:gravity="center"
android:src="@drawable/logo" />
</item>
</layer-list>
windowSplashScreenBrandingImage要求宽200dp高80dp,可以先用xml试一下是否被裁剪,也可以让UI直接出图对应比例的。
想维持启动页可以使用:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
splashScreen.setOnExitAnimationListener {
}
}