Error : <item> tag requires a 'drawable' attribute or child tag defining a drawable
The error has to do with the format of your xml, you are setting something like
android:background="@drawable/item_bg_selector"
What the error is telling you is that it should be like this
android:drawable="@drawable/item_bg_selector"
I've experienced the same Exception for a different problem.
I was trying to use a color selector for the View
's android:background
:
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/tab_background_selector" />
<!-- /res/color/tab_background_selector.xml -->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/white" android:state_checked="true" />
<item android:color="@color/light_blue" />
</selector>
Moving the selector to the drawable folder and changing android:color
to android:drawable
solved the problem.
Also, the background definition in the Layout needs to be changed to android:background="@drawable/tab_background_selector"
Here is the final selector:
<!-- /res/drawable/tab_background_selector.xml -->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/white" android:state_checked="true" />
<item android:drawable="@color/light_blue" />
</selector>
I had the same error and switching the order of the attributes (as it was suggested in the this answer to this other question) to have the drawable the first one solved the problem.
In your case would be switching:
<item android:state_selected="true"
android:drawable="@drawable/item_background_selected" />
to:
<item android:drawable="@drawable/item_background_selected"
android:state_selected="true" />