windowSplashScreenAnimationDuration 对持续时间没有直接影响。您使用 SplashScreenView#getIconAnimationDuration 检索持续时间值,并在您自己的业务逻辑中使用该值。
来自https://developer.android.com/guide/topics/ui/splash-screen#suspend-drawing
使用 windowSplashScreenAnimationDuration 来表示闪屏图标动画的持续时间。设置此项不会对显示初始屏幕的实际时间产生任何影响,但您可以在使用 SplashScreenView#getIconAnimationDuration 自定义初始屏幕退出动画时检索它。有关更多详细信息,请参阅下一节中的将初始屏幕保留更长时间。
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// ...
// Add a callback that's called when the splash screen is animating to
// the app content.
splashScreen.setOnExitAnimationListener { splashScreenView ->
// Create your custom animation.
val slideUp = ObjectAnimator.ofFloat(
splashScreenView,
View.TRANSLATION_Y,
0f,
-splashScreenView.height.toFloat()
)
slideUp.interpolator = AnticipateInterpolator()
slideUp.duration = 200L
// Call SplashScreenView.remove at the end of your custom animation.
slideUp.doOnEnd { splashScreenView.remove() }
// Run your animation.
slideUp.start()
}
}
// Get the duration of the animated vector drawable.
val animationDuration = splashScreenView.iconAnimationDuration
// Get the start time of the animation.
val animationStart = splashScreenView.iconAnimationStart
// Calculate the remaining duration of the animation.
val remainingDuration = if (animationDuration != null && animationStart != null) {
(animationDuration - Duration.between(animationStart, Instant.now()))
.toMillis()
.coerceAtLeast(0L)
} else {
0L
}