Android drawable xml Unable to convert to color Exception for API 10

In my application, I define the color attributes that I set in the custom theme:

RES / values ​​/ attrs.xml

<resources> <attr name="bbColorPrimary" format="color|reference" /> </resources> 

RES / values ​​/ colors.xml

 <resources> <color name="white">#ffffff</color> </resources> 

RES / values ​​/ style.xml

 <style name="MyStyle" parent="@style/Theme.AppCompat.NoActionBar"> <item name="bbColorPrimary">@color/white</item> </style> 

Res / draw / background.xml

 <selector xmlns:android="http://schemas.android.com/apk/res/android" > <item android:state_pressed="true"> <shape> <solid android:color="?attr/bbColorPrimary" /> </shape> </item> <item> <shape> <solid android:color="@color/transparent" /> </shape> </item> </selector> 

res/drawable/background.xml set as the background of some button. The application crashes when bloating the res/drawable/background.xml file with the following exception:

 ... Caused by: java.lang.UnsupportedOperationException: Can't convert to color: type=0x2 at android.content.res.TypedArray.getColor(TypedArray.java:326) at android.graphics.drawable.GradientDrawable.inflate(GradientDrawable.java:748) at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:787) at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:172) .... 

It works at API levels above 10. If I remove ?attr/bbColorPrimary , it works fine, although many other calls to ?attr/.. are set in other resource files. I do not use any resource folders for the version.

What am I doing wrong here?

+6
source share
1 answer

I found an answer to SO, noting that ?attr/.. not supported in xml drawings. See here: fooobar.com/questions/77233 / ...

This seems to be true, at least for API <= 10.

+6
source

Source: https://habr.com/ru/post/978253/


All Articles