I want to have two themes for my application. For this, I defined some attributes, for example:
<attr format="color" name="item_background" />
Then I created both themes, for example:
<style name="ThemeA"> <item name="item_background">#123456</item> </style> <style name="ThemeB"> <item name="item_background">#ABCDEF</item> </style>
This method works great, which allows me to easily create and modify multiple themes. The problem is that it seems that it can only be used in views, and not in Drawables .
For example, a link to a value from a view inside a layout works:
<TextView android:background="?item_background" />
But doing the same in Drawable does not:
<shape android:shape="rectangle"> <solid android:color="?item_background" /> </shape>
I get this error when starting the application:
java.lang.UnsupportedOperationException: Can't convert to color: type=0x2
If I use hard code instead of ?item_background , it works, but this does not allow me to use my themes. I also tried ?attr:item_background , but the same thing happens.
How can i do this? And why does it work in Views, but not in Drawables? I cannot find this restriction anywhere in the documentation ...
android android-drawable android-theme
MM Nov 07 2018-11-11T00: 00Z
source share