Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exception android.content.res.Resources$NotFoundException: File res/color/selector_tab_blue_white.xml from drawable resource ID #0x7f0601d8

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" />

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

like image 397
Deepak Rajput Avatar asked Oct 21 '25 16:10

Deepak Rajput


1 Answers

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"/>

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

For example, 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>

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

   app:tabBackground="@drawable/selector_tab_blue_white_background"

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

like image 159
Sampson Avatar answered Oct 23 '25 05:10

Sampson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!