异常android.content.res.Resources $ NotFoundException:来自可绘制资源ID#0x7f0601d8的文件res/color/selector_tab_blue_white.xml [英] Exception android.content.res.Resources$NotFoundException: File res/color/selector_tab_blue_white.xml from drawable resource ID #0x7f0601d8

查看:456
本文介绍了异常android.content.res.Resources $ NotFoundException:来自可绘制资源ID#0x7f0601d8的文件res/color/selector_tab_blue_white.xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用tabLayout作为

I am using tabLayout as

  <com.google.android.material.tabs.TabLayout
                    android:id="@+id/tabLayoutSubscriptionDays"
                    style="@style/CustomTabLayoutTextSizeSix"
                    android:layout_width="match_parent"
                    android:layout_height="@dimen/_40sdp"
                    android:background="@color/white"
                    app:tabBackground="@color/selector_tab_blue_white"
                    app:tabIndicatorColor="@color/transparent"
                    app:tabMode="fixed"
                    app:tabSelectedTextColor="@color/white"
                    app:tabTextColor="@color/black" />

在某些设备中,我遇到异常,例如:android.content.res.Resources $ NotFoundException:来自可绘制资源ID#0x7f0601d8的文件res/color/selector_tab_blue_white.xml

In some devices i am getting exception as like : android.content.res.Resources$NotFoundException: File res/color/selector_tab_blue_white.xml from drawable resource ID #0x7f0601d8

这是我的选择器,它位于颜色目录中:

This is my selector which is in color directory:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/blue_4880ff" android:state_selected="true" />
<item android:color="@color/white" />
</selector>

我已经尝试过很多解决方案,例如:

I have tried so many solutions regarding this like:

  defaultConfig {
    vectorDrawables.useSupportLibrary = true
}

AppCompatDelegate.setCompatVectorFromResourcesEnabled(true)

我尝试过的这些解决方案.

These solutions I have tried.

如果有人可以帮助,那就太好了.谢谢

If anyone can help then it will be so good. Thanks

推荐答案

app:tabBackground属性需要引用,这意味着它必须是可绘制资源.

The app:tabBackground attribute requires a reference meaning it must be to a drawable resource.

    <!-- Reference to a background to be applied to tabs. -->
    <attr format="reference" name="tabBackground"/>

您将要创建一个图形,该图形的形状会引用所需的颜色(在本例中为color/selector_tab_blue_white.xml).

You will want to create a drawable with a shape that references the desired color (in this case, color/selector_tab_blue_white.xml).

例如,drawable/selector_tab_blue_white_background.xml:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="@color/selector_tab_blue_white" />
</shape>

在布局xml中,将app:tabBackground引用属性更改为:

In your layout xml change the app:tabBackground reference attribute to:

   app:tabBackground="@drawable/selector_tab_blue_white_background"

即使所需的颜色color/selector_tab_blue_white.xml是颜色选择器,这也对我有用.

This worked for me even when the desired color color/selector_tab_blue_white.xml is a color selector.

这篇关于异常android.content.res.Resources $ NotFoundException:来自可绘制资源ID#0x7f0601d8的文件res/color/selector_tab_blue_white.xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆