10

I´m Using com.android.support:appcompat-v7:22.1.1

This attribute android:buttonStyle is not setting that style for every button, I need to set android:theme="@style/AppTheme.Button" manually on each button.

   <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:buttonStyle">@style/AppTheme.Button</item>
   </style>

What do I need to do to set a general style for it?

Daniel Gomez Rico
  • 15,026
  • 20
  • 92
  • 162

3 Answers3

19

Use buttonStyle insteadof android:buttonStyle in your theme

LenaYan
  • 746
  • 6
  • 7
  • 3
    when should I use `android:` attribute name? – Daniel Gomez Rico May 01 '15 at 13:20
  • 4
    @danielgomezrico From appcompat v21+ you should drop them: http://stackoverflow.com/a/26815521/479478 – Eric Chen Jun 04 '15 at 17:02
  • 2
    @LenaYan Error:(10, 21) No resource found that matches the given name: attr 'buttonStyle'. Which resource should be used here? As original question states android:buttonStyle doesn't work either – vir us Aug 12 '15 at 13:31
2

Similar to @danielgomezrico answer but without having two style files:

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <!-- android:buttonStyle for v21+ and buttonStyle for the rest -->
    <item name="buttonStyle">@style/MyCustomButton</item>
    <item name="android:buttonStyle">@style/MyCustomButton</item>
    <item name="colorButtonNormal">@color/my_color_accent</item>
</style>

<style name="MyCustomButton" parent="Base.Widget.AppCompat.Button">
    <item name="android:textColor">#ffffff</item>
</style>

0

I ended up setting background color with colorButtonNormal attribute and other style attributes with buttonStyle.

values/style.xml:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
   <item name="colorPrimary">@color/my_color_primary</item>
   <item name="colorPrimaryDark">@color/my_color_primary_dark</item>
   <item name="colorAccent">@color/my_color_accent</item>
 </style>

 <style name="AppTheme.Base">
   <item name="colorButtonNormal">@color/my_color_accent</item>
   <item name="buttonStyle">@style/Button</item>
 </style>

 <style name="Button" parent="Base.Widget.AppCompat.Button">
   <item name="android:textColor">@color/my_color_white</item>
 </style>

values-v21/style.xml

  <style name="AppTheme.Base">
    <item name="android:colorButtonNormal">@color/my_color_accent</item>
    <item name="android:buttonStyle">@style/Button</item>
  </style>

And then all the buttons have the background/text color I wanted without setting style on each one.

Daniel Gomez Rico
  • 15,026
  • 20
  • 92
  • 162