启动画面 API 未显示图标。

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

build.gradle

android {
    compileSdkVersion 31
    ...
}

dependencies {
    implementation "androidx.core:core-splashscreen:1.0.0-alpha01"
    ...
}

values-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>

AndroidManifest.xml

<application
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme">
    ...
</application>

MainActivity.kt

class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen()
    ...
}
1个回答

9

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

当从Android Studio启动应用程序时,由启动画面API设置的图标不起作用。如果应用程序被关闭然后重新启动,则图标会正确显示。

这个错误可能是由于此库的早期alpha状态而存在,并且据称将在未来版本的Splashscreen API中修复。


有相同的问题,但图标从未显示,即使使用alpha2。 - ueen
我遇到了与1.0.0版本相同的错误/问题。 - userVadim

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接