Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Widget.AppCompat.Button colorButtonNormal shows gray

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

like image 860
Daniel Gomez Rico Avatar asked Apr 25 '15 04:04

Daniel Gomez Rico


People also ask

Is there an appcompat-v7 button style?

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.

How to change the background color of a button on Android?

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+.

How to get ripple effect on background color of button?

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.

Is there a widget style to set as parent for mybuttonstyle?

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.


1 Answers

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

like image 84
Oleksandr Avatar answered Oct 20 '22 11:10

Oleksandr