After searching and trying, I got a hint that there are some things you can do and some things you cannot .
You can
a) Define your own attributes in attrs
<?xml version="1.0" encoding="utf-8"?> <resources> <attr name="color_gallery_backround" format="color|reference" /> </resources>
b) Define your values ββin your styles. xml
<style name="AppBaseThemeDark" parent="android:Theme.Black"> <item name="color_gallery_backround">@color/White</item> </style> <style name="AppBaseThemeWhite" parent="android:Theme.Light"> <item name="color_gallery_backround">@color/Black</item> </style>
c) Use them in any representation how? color_gallery_backround or? attr / color_gallery_backround for example
android:background="?attr/color_gallery_backround"
YOU DONT BE
a) You cannot access this attribute from custom drawings because they are not valid during inflation
therefore you can not use? attr / color_gallery_backround here:
customshape.xml
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <solid android:color="**?attr/color_gallery_backround**" /> <stroke android:width="2dp" android:color="@color/Black" /> </shape>
b) You cannot access this attribute in a view that will be inflated during (e.g.) ListView as a ListItem
Thus, the topic of "support" of attributes, at least prior to API 10, has limits of depth.
Solutions
As suggested, you need to create DUAL separate drawings using different colors and configure the attributes to link to these drawings in accordance with the theme:
attrs.xml
<?xml version="1.0" encoding="utf-8"?> <resources> <attr name="rounded_background" format="reference" /> </resources>
and for each topic that can be used in styles.xml:
<resources> <style name="AppBaseThemeDark" parent="android:Theme.Black"> <item name="rounded_background">@drawable/round_rect_shape_dark</item> </style> <style name="AppBaseThemeLight" parent="android:Theme.Light"> <item name="rounded_background">@drawable/round_rect_shape_white</item> </style> </resources>
Now you can reference your drawable as? rounded_background, and let the theme select it.
For bloated views in a ListView listitem, you must programmatically set the colors.