I have an attrs.xml file as follows:
<?xml version="1.0" encoding="utf-8"?> <resources> <attr name="butBackColor" format="reference|color" /> </resources> Styles.xml contains:
<style name="GreyButtonTheme" parent="android:style/Widget.Button"> <item name="butBackColor">#3D3D3D</item> </style> I have custom_button.xml which contains a drawable selector:
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> ... <item android:left="5dp" android:right="5dp" android:top="5dp" android:bottom="5dp"> <shape> <solid android:color="@color/butGreyBack" /> <padding android:left="10dp" android:top="10dp" android:right="10dp" android:bottom="10dp" /> </shape> </item> Finally, I have a layout which contains a Button which I want to use my style with:
The code snippets above work fine for me - but when I change:
<solid android:color="@color/butGreyBack" /> to:
<solid android:color="?butBackColor" /> ..then I get an "Error inflating class " exception. Why is the custom_button.xml selector failing? What do I need to do to get the ?butBackColor attribute to work?
The reason I have implemented it this way is that I would like to use different styles (colours) for different sets of buttons.
Here is the project which may be of use to somebody who wants a file browser dialog box: