I followed the tutorial on creating custom buttons . If I applied the style to the button directly, this will work, but if I applied the style to the theme using android:buttonStyle , this will not work.
Example. Here is the xml style with the button style applied: Values โโ/styles.xml
<resources> <style name="MyTheme" parent="android:Theme.Light"> <item name="android:buttonStyle">@style/ButtonText</item> </style> <style name="ButtonText"> <item name="android:layout_width">fill_parent</item> <item name="android:layout_height">wrap_content</item> <item name="android:textColor">#ffffff</item> <item name="android:background">@drawable/ruddy_orange_button</item> </style> </resources>
range hood / ruddy_orange_button.xml:
<item android:state_pressed="true"> <shape> <solid android:color="#70c656" /> <stroke android:width="1dp" android:color="#53933f" /> <corners android:radius="3dp" /> <padding android:bottom="10dp" android:left="10dp" android:right="10dp" android:top="10dp" /> </shape> </item> <item> <shape> <gradient android:angle="270" android:endColor="#fd4d4d" android:startColor="#f24b4b" /> <stroke android:width="1dp" android:color="#f04a4a" /> <corners android:radius="4dp" /> <padding android:bottom="10dp" android:left="10dp" android:right="10dp" android:top="10dp" /> </shape> </item> </selector>
However, if I apply the style directly to the button, it works:
<Button android:layout_width="fill_parent" android:layout_height="wrap_content" style="@style/ButtonText" android:text="hello there" />
Any pointers to what I'm doing wrong here?
I tested this on Android 2.3.3
The source is on github .
source share