启动画面 API 不显示图标

Phi*_*ich 3 android androidx android-12

我们目前正在通过新的 Splashscreen API 实现启动屏幕。我们正在遵循迁移指南。背景颜色设置正确(通过windowSplashScreenBackground),但图标在模拟器和物理设备上均不可见。

构建.gradle

android {
    compileSdkVersion 31
    ...
}

dependencies {
    implementation "androidx.core:core-splashscreen:1.0.0-alpha01"
    ...
}
Run Code Online (Sandbox Code Playgroud)

值-v31/themes.xml

<style name="AppTheme" parent="Theme.SplashScreen">
    <item name="postSplashScreenTheme">@style/AppThemeCompat</item>
    <item name="windowSplashScreenBackground">@android:color/black</item>
    <item name="windowSplashScreenAnimatedIcon">@mipmap/ic_launcher</item>
    <item name="windowSplashScreenAnimationDuration">200</item>
</style>
Run Code Online (Sandbox Code Playgroud)

AndroidManifest.xml

<application
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme">
    ...
</application>
Run Code Online (Sandbox Code Playgroud)

MainActivity.kt

class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen()
    ...
}
Run Code Online (Sandbox Code Playgroud)

Phi*_*ich 9

我直接回答这个问题,因为我们在一两个小时内找到了问题的解决方案,可以从其他开发人员那里节省下来:

从 Android Studio 启动应用程序时,Splashscreen API 设置的图标不起作用。如果应用程序关闭然后重新启动,图标将正确显示。

由于该库处于早期 alpha 状态,该错误可能存在,据称将在 Splashscreen API 的未来版本中修复。