buttonStyle not working for 22.1.1

馋奶兔 提交于 2019-12-05 02:03:00

Use buttonStyle insteadof android:buttonStyle in your theme

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>

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!