[Android:Resources $ NotFoundException,将可绘制对象添加到styles.xml中

问题描述 投票:0回答:1

我有这个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在可绘制文件夹中是绝对

enter image description here

Android Studio正在建议该文件。

我的可绘制文件夹:

enter image description here

android file exception splash-screen filenotfoundexception
1个回答
0
投票

解决方案:

将位图用于可绘制的项目mipmap以正确加载。

     <item>
          <bitmap
                 android:gravity="center"
                android:src="@mipmap/your_image" />
      </item>
© www.soinside.com 2019 - 2024. All rights reserved.