从Android 12开始,开发者可以轻松地自定义应用的启动画面。以下是一些示例代码,可用于自定义Splash Screen API:
dependencies { implementation 'androidx.core:core-splashscreen:1.0.0-alpha01' }
import androidx.core.splashscreen.SplashScreen
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState)
// 设置启动画面样式,这里使用红色背景和白色字体 val splashScreen: SplashScreen = SplashScreen.installSplashScreen(this) splashScreen.setContentView(R.layout.activity_splash_screen) splashScreen.setBackgroundColor(Color.RED) splashScreen.setLogo(R.drawable.ic_splash_logo) splashScreen.setAnimation(SplashScreen.Animation.SLIDE_IN_TOP) splashScreen.setFixedOrientationPortrait() splashScreen.setExitAnimation(SplashScreen.SplashScreenExitAnimation.SLIDE_OUT_BOTTOM) }
}
...
...
其中“AppTheme”是您应用程序的主题,“MainActivity”是您的主Activity,“SplashScreenTheme”是您的启动画面主题。
这些代码示例可以帮助您自定义Android 12中的启动画面API。