Android 12中的splash screen是一种启动屏幕,用于在应用程序开始初始化之前显示。其中的setKeepVisibleCondition方法为设置条件,控制splash screen的显示时间。当满足条件时,splash screen将被移除。
下面给出一个示例代码,使用setKeepVisibleCondition方法来设置条件:
Window window = getWindow();
SplashScreen splashScreen = window.getSplashScreen();
// Set a condition for when to remove the splash screen.
splashScreen.setKeepVisibleCondition(() -> {
if (myCondition) {
// Return false to remove the splash screen.
return false;
} else {
// Return true to keep the splash screen visible.
return true;
}
});
其中,myCondition为自定义的条件,当满足该条件时,splash screen将被移除,应用程序开始初始化。