I have values:styles.xml
with:
<style name="AppTheme.Button" parent="Base.Widget.AppCompat.Button"> <item name="colorButtonNormal">@color/my_color</item> <item name="android:textColor">@android:color/white</item> </style>
and values-v21:styles.xml
with:
<style name="AppTheme.Button" parent="Base.Widget.AppCompat.Button"> <item name="android:colorButtonNormal">@color/my_color</item> <item name="android:textColor">@android:color/white</item> </style>
And app style with
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> <item name="android:buttonStyle">@style/AppTheme.Button</item> </style>
But the colors appears grey instead of @color/my_color
And yes, there's no appcompat-v7 button style (well, at least not yet). This assumes you're OK with Holo button on platforms older than Lollipop. It feels unobtrusive and if you can do without ripples, it should be just fine. If you want ripples I suggest you google for a third party lollipop button library. Thanks.
This solution is based on AppCompat version 25.1.0, tested on API25, API16 emulators and a Google Pixel running Nougat 7.1.1. Change the background color using android:backgroundTint By using the android :backgroundTint, your button gets the color and the ripple effect. Unfortunately, this works only on API21+.
By using the android :backgroundTint, your button gets the color and the ripple effect. Unfortunately, this works only on API21+. On previous version of AppCompat (not sure which) , app :backgrountTint works fine on all API levels, you get a ripple on post-API21 and a StateListDrawable on pre-API21.
However, there is no Widget.AppCompat.Button style to set as the parent for MyButtonStyle. If I use android:Widget.Button, then all my buttons look like the old crappy style. I tried various other AppCompat themes like TextAppearance.AppCompat.Button, but they do not work.
To customize one button only set android:theme="@style/AppTheme.Button" to your button.
<Button android:theme="@style/AppTheme.Button" />
Define your style as you did in your question
<style name="AppTheme.Button" parent="Base.Widget.AppCompat.Button"> <item name="colorButtonNormal">@color/my_color</item> </style>
[EDIT]
See GitHub demo here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With