Using buttonStyle as a theme does not work, but if attached to the button directly

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"> <!-- the button gets styled but is no longer clickable if i do it like this --> <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 .

+6
source share
2 answers

Try the following:

 <style name="ButtonText" parent="@android:style/Widget.Button"> 
+9
source

I also had this problem. I hope the tip will tell you

appcompat v21 + you should use buttonStyle instead of android:buttonStyle in your theme

+6
source

Source: https://habr.com/ru/post/903394/


All Articles