Underline Android Theme not working with Color Drawable (bug?)
So I am trying to create
one that uses a background color as the background. Following the instructions in this SO answer , I first define my color in res / values /colors.xml:
Then I define the attribute in res / values /attrs.xml:
<attr name="drawable_selected" format="reference" />
and then in my theme, I set an attribute for my color (res / values / styles.xml):
<style name="AppThemeWhite" parent="AppTheme"> <item name="drawable_selected">@color/selected</item> </style>
Finally, I am referencing the attribute in my selector (res / drawable / selected_background):
<selector> <item android:state_activated="true" android:drawable="?drawable_selected" /> <item android:drawable="@android:color/transparent" /> </selector>
When I run this, I get an error
Binary XML file line #2: Error inflating class <unknown>
when I try to inflate a class that uses a selector. However, when I change the selector
to reference the drawable using directly
, it works.
Is this a bug or am I doing something wrong?
If I add a color attribute (res / values /attrs.xml)
<attr name="selected_color" format="color" />
and define the color in my theme (res / values /styles.xml)
I can change the color usable for change based on them (res / values /colors.xml)
and reference the drawable directly using
in my selector. However, this also crashes! And changing the color returned by the hardcoded value
fixes it. It seems like this whole theme system is pretty broken ...
source to share
Yes, references to custom theme attributes from drawable (or colors) don't work on Android at this time.
You can see more details about an issue that was reported long ago here: https://code.google.com/p/android/issues/detail?id=26251
As you can see, they finally resolved it in the Android L release, but somewhere below L, such a link failed.
To work around this problem, you need to do something like this:
<selector> <item android:state_activated="true" android:drawable="@color/selected" /> <item android:drawable="@android:color/transparent" /> </selector>
defined as at the beginning of your post:
source to share