添加启动画面

如果您的应用实现了自定义启动画面或使用启动器主题,请将应用迁移到 Jetpack 中提供的 SplashScreen 库,确保它在所有版本的 Wear OS 上都能正确显示。

请参阅本页中的分步实现说明,了解如何使用 SplashScreen 库来添加启动画面,使屏幕符合设计准则

添加依赖项

将以下依赖项添加到应用模块的 build.gradle 文件:

Groovy

dependencies {
    implementation "androidx.core:core-splashscreen:1.2.0"
}

Kotlin

dependencies {
    implementation("androidx.core:core-splashscreen:1.2.0")
}

请确保您使用的是 1.0.1 或更高版本,以便获得对默认 Wear OS 尺寸的支持。

添加主题

res/values/styles.xml 中创建启动画面主题。父元素取决于图标的形状:

  • 如果图标是圆形,请使用 Theme.SplashScreen
  • 如果图标是其他形状,请使用 Theme.SplashScreen.IconBackground

使用 windowSplashScreenBackground 能够以单一黑色填充背景。将 postSplashScreenTheme 的值设置为 activity 应使用的主题,并将 windowSplashScreenAnimatedIcon 设置为可绘制对象或带动画的可绘制对象:

<resources>
    <style name="Theme.App" parent="@android:style/Theme.DeviceDefault" />