Android:将可绘制对象添加到 styles.xml 时出现 Resources$NotFoundException

Jak*_*kob 3 android exception file splash-screen filenotfoundexception

我有这个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>
Run Code Online (Sandbox Code Playgroud)

然后我想将其添加为<item>to styles.xml

<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
    <item name="android:windowBackground">@drawable/splash_screen</item>
</style>
Run Code Online (Sandbox Code Playgroud)

但这会抛出:

Caused by: android.content.res.Resources$NotFoundException: File res/drawable/splash_screen.xml from drawable resource ID #0x7f070099
Run Code Online (Sandbox Code Playgroud)

当我尝试时:

<item name="android:windowBackground">@color/colorPrimary</item>
Run Code Online (Sandbox Code Playgroud)

我的代码工作正常并以 colorPrimary 显示屏幕。

我该如何修复它?

我尝试重建、清理、重新启动 Android Studio 以及 SO 上的每一篇文章。没有任何帮助。

编辑

splash_screen.xml肯定是在drawable文件夹中。

在此输入图像描述

Android Studio 正在建议该文件。

我的绘图文件夹:

在此输入图像描述

Md.*_*man 5

您必须像在第一个标签中那样在项目标签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>
Run Code Online (Sandbox Code Playgroud)

除此之外,始终发布异常的完整堆栈跟踪。实际的异常清楚地表明了问题,如下所示:

引起原因:org.xmlpull.v1.XmlPullParserException:二进制 XML 文件第 6 行:标记需要“drawable”属性或定义可绘制对象的子标记