我做了这样的事情。首先删除默认drawable
<style name="Theme.App.Starting" parent="Theme.SplashScreen">
<item name="windowSplashScreenBackground">@color/...</item>
<item name="windowSplashScreenAnimatedIcon">@android:color/transparent</item>
<item name="postSplashScreenTheme">@style/AppTheme</item>
</style>
然后膨胀您的自定义启动视图
class MainActivity : AppCompatActivity(), SplashScreen.OnExitAnimationListener {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val installSplashScreen = installSplashScreen()
installSplashScreen.setOnExitAnimationListener(this)
setContentView(R.layout.activity_main)
}
override fun onSplashScreenExit(splashScreenViewProvider: SplashScreenViewProvider) {
val view = splashScreenViewProvider.view
if (view is ViewGroup) {
val binding = ActivityMainSplashBinding.inflate(layoutInflater,view, true)
// Do what you want with your inflated view
animate(view) {
// Remove splash
splashScreenViewProvider.remove()
}
}
}
private fun animate(view: View, doOnFinish: () -> Unit) {
view.animate()
.withEndAction(doOnFinish)
.start()
}
}
最后记得调用 splashScreenViewProvider.remove() 来移除飞溅。