我有带有白色状态栏和导航栏的应用程序。我已经定义了这样的 Splash 主题。
<style name="Theme.MySplash" parent="Theme.SplashScreen">
<item name="windowSplashScreenBackground">#00f</item>
<item name="windowSplashScreenAnimatedIcon">@drawable/ic_baseline_play_arrow_24</item>
<item name="windowSplashScreenAnimationDuration">200</item>
<item name="postSplashScreenTheme">@style/Theme.AppTheme</item>
</style>
<style name="Theme.AppTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<item name="android:statusBarColor">#fff</item>
<item name="android:navigationBarColor">#fff</item>
</style>
主要活动
class MainActivity : AppCompatActivity() {
var keepSplashScreen = true
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val splashScreen = installSplashScreen()
splashScreen.setOnExitAnimationListener { splashScreenProvider ->
val fadeAnim = ObjectAnimator.ofFloat(
splashScreenProvider.view, View.ALPHA, 1f, 0f
)
fadeAnim.duration = 4000L
fadeAnim.interpolator = AccelerateInterpolator()
fadeAnim.doOnEnd { splashScreenProvider.remove() }
fadeAnim.start()
}
splashScreen.setKeepVisibleCondition { keepSplashScreen }
setContentView(R.layout.activity_main)
Handler(Looper.getMainLooper()).postDelayed({
keepSplashScreen = false
}, 3000)
}
}
SplashTheme
在设备 Android 12 (Pixel 4XL) 上运行良好,但在 Android 8 (Xiomi A2)上运行SplashTheme
时,它不会显示全屏。
从这个视频中,当SplashScreen
开始存在(淡入淡出动画)时,会显示白色状态栏和导航栏(在 Android 12 上,SplashScreen
存在时始终全屏)。如何SplashScreen
在 Android < 12 上始终全屏显示?