android - Android:在将 drawable 添加到 styles.xml 时出现 Resources$NotFoundException
问题描述
我有这个splash_screen.xml
:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@color/colorPrimary"/>
<item
android:gravity="center"
android:src="@mipmap/ic_launcher"/>
</layer-list>
然后我想将其添加<item>
为styles.xml
:
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">@drawable/splash_screen</item>
</style>
但这会引发:
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/splash_screen.xml from drawable resource ID #0x7f070099
当我尝试:
<item name="android:windowBackground">@color/colorPrimary</item>
我的代码工作正常,并在 colorPrimary 中显示一个屏幕。
我该如何解决?
我尝试重建、清理、重新启动 Android Studio 以及 SO 上的每个帖子。没有任何帮助。
编辑
splash_screen.xml
肯定在drawable文件夹中。
Android Studio 建议使用该文件。
我的可绘制文件夹:
解决方案
您必须像在第一个中一样在您的项目标签android:drawable
中使用。android:src
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@color/colorPrimary"/>
<item
android:gravity="center"
android:drawable="@mipmap/ic_launcher"/>
</layer-list>
除此之外,始终发布异常的完整堆栈跟踪。实际异常清楚地表明了如下问题:
原因:org.xmlpull.v1.XmlPullParserException:二进制 XML 文件第 6 行:标签需要“drawable”属性或定义可绘制对象的子标签
推荐阅读
- python - 无法将环境变量传递给 docker 容器
- discord.py - discord.py on_command_error 帮助理解错误
- html - 使用 JQuery 对同一元素执行多个函数
- python - 错误:Series 的真值不明确
- python - 从 json 文件传递 mongodb 查询以在 python 中执行
- sml - SML: Operator ```::``` 是正确的联想,应该用作 ```
:: - ```?
- c++ - C ++中的双冒号是什么意思?
- mql5 - 从 MQL5 中的 csv 文件计算数组的 RSI?
- mobile - 如何在 DialogFlow Mobile 平台中设置基于时间访问的响应消息?
- python - AWS Lambda 提取理解记录数据