找不到 windowSplashScreenAnimatableIcon

rek*_*ire 6 android splash-screen styling android-12

我想在 Android 12 上自定义启动屏幕,但收到 AAPT 错误:

AAPT: error: style attribute 'android:attr/windowSplashScreenAnimatableIcon' not found.
Run Code Online (Sandbox Code Playgroud)

这是样式的相关部分:

AAPT: error: style attribute 'android:attr/windowSplashScreenAnimatableIcon' not found.
Run Code Online (Sandbox Code Playgroud)

这就是文档中提到的属性。

以下是我正在使用的构建工具库的概述:

compileSdk="android-S"
minSdk=21
targetSdk="S"
buildTools='31.0.0-rc4'
Run Code Online (Sandbox Code Playgroud)

我使用 Android Studio 北极狐 | 2020.3.1 Beta 1 仅供记录。

有人可以指出我做错了什么吗?

rek*_*ire 5

该文档似乎是错误/过时的。正确的属性是:

<item name="android:windowSplashScreenAnimatedIcon">@drawable/ic_splash</item>
Run Code Online (Sandbox Code Playgroud)

正确的属性列在R.attr中。


在这个答案的先前版本中,我有一种方法可以让闪屏像以前一样工作,但是这不再起作用了。

今天我建议使用splash compat库和这种风格:

<style name="SplashTheme" parent="Theme.SplashScreen">
    <item name="windowSplashScreenBackground">@color/ic_launcher_background</item>
    <item name="windowSplashScreenAnimatedIcon">@drawable/ic_launcher_foreground</item>
    <item name="postSplashScreenTheme">@style/Your.Normal.Theme</item>
</style>
Run Code Online (Sandbox Code Playgroud)

这有两个假设:您使用具有默认命名的自适应启动器图标。就我而言,ic_launcher_background它是纯色,这就是为什么我使用颜色而不是可绘制前缀。我希望这对其他人有帮助。

这是Google 的启动迁移指南。