【问题标题】:windowSplashScreenAnimatableIcon not found找不到窗口SplashScreenAnimatableIcon
【发布时间】:2021-10-13 23:12:07
【问题描述】:

我想在 Android 12 上自定义我的启动画面,但我收到了 AAPT 错误:

AAPT: error: style attribute 'android:attr/windowSplashScreenAnimatableIcon' not found.

以下是样式的相关部分:

<style name="SplashTheme" parent="@style/Theme.MaterialComponents.DayNight.NoActionBar">
    <item name="android:windowSplashScreenAnimatableIcon">@drawable/ic_splash</item>
</style>

也就是documentation中提到的属性。

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

compileSdk="android-S"
minSdk=21
targetSdk="S"
buildTools='31.0.0-rc4'

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

谁能指出我做错了什么?

【问题讨论】:

标签: android splash-screen styling android-12


【解决方案1】:

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

<item name="android:windowSplashScreenAnimatedIcon">@drawable/ic_splash</item>

R.attr class 中列出了正确的属性。


在此答案的先前版本中,我有办法让启动画面像以前一样工作,但这不再起作用了。

今天我建议使用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>

这有两个假设,即您使用具有默认命名的自适应启动器图标。在我的情况下,ic_launcher_background 是纯色,这就是我使用颜色而不是可绘制前缀的原因。我希望这对其他人有所帮助。

这是来自 Google 的 splash migration 指南。

【讨论】:

  • 我正在撰写答案。猜你更快。
  • FWIW,在 Beta 2 中,@null 图标似乎不起作用 - 应用程序图标仍然显示。
  • @rekire 这还能用吗?我已经用我现有的splash drawable尝试了这个,但我只能在SplashScreen上看到颜色,而不是drawable。这是我的代码:我的 values-v31 styles.xml 文件:``` language-all ```
  • 似乎您可以使用兼容库在旧平台上保持启动画面行为,但在新平台上不再适用。
【解决方案2】:

如果您在 pubspec.yaml 中添加 android12: true 会发生这种情况

【讨论】:

【解决方案3】:

对于在自定义启动画面时遇到问题的任何人,请确保您使用的是正确的父主题

而不是

<style name="SplashTheme" parent="@style/Theme.MaterialComponents.DayNight.NoActionBar">
    <item name="android:windowSplashScreenAnimatableIcon">@drawable/ic_splash</item>
</style>

使用

<style name="SplashTheme" parent="Theme.SplashScreen">
    <item name="android:windowSplashScreenAnimatableIcon">@drawable/ic_splash</item>
    <item name="postSplashScreenTheme">@style/Your.Normal.Theme</item>
</style>

【讨论】:

猜你喜欢
  • 2016-12-22
  • 2017-06-28
  • 2021-08-24
  • 2019-12-18
  • 2017-08-14
  • 1970-01-01
  • 1970-01-01
  • 2012-06-07
  • 2010-10-18
相关资源
最近更新 更多