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
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.
You have to add that drawable file in 2 folders along with drawable folder:
drawable
drawable-v24
Then it will not crash on any device.
Hope this helps
Please Follow below steps to resolve this issue..
In declare-styleable of TabLayout
<attr format="reference" name="tabBackground"/>
So in your case, modify the following
<item android:color="@color/blue_4880ff" android:state_selected="true" /> <item android:color="@color/white" />
into
<item android:drawable="@color/blue_4880ff" android:state_selected="true" /> <item android:drawable="@color/white" />
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.