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?
source share