闪屏API不显示图标



我们目前正在通过新的splashscreen API实现splashscreen。我们遵循迁移指南。背景颜色设置正确(通过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()
...
}

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

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

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

最新更新