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 application style with

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

But colors look gray, not @color/my_color

+50
android appcompat
Apr 25 '15 at 4:11
source share
9 answers

To configure one button, install only android: theme = "@ style / AppTheme.Button" on your button.

 <Button ...... android:theme="@style/AppTheme.Button" ...... /> 

Define your style as in your question

 <style name="AppTheme.Button" parent="Base.Widget.AppCompat.Button"> ........ <item name="colorButtonNormal">@color/my_color</item> ........ </style> 

[EDIT]

Watch the github demo here

+50
Jun 04 '15 at 13:59 on
source share

Use Widget.AppCompat.Button.Colored as the parent for your style.

 <style name="RedButton" parent="Widget.AppCompat.Button.Colored"> <item name="android:textColor">@color/white</item> <item name="colorButtonNormal">@color/red</item> </style> 

Use android:theme , not style in button definitions:

 <Button android:theme="@style/RedButton"/> 

See AppCompat v21> Theming and Android Support Library v22.1 - AppCompat for blogs. (note on the second post, android:theme supported in API11-, it just does not automatically inherit from the parent, you will have to point it to each child device, not the problem, but it's worth mentioning - see Chris Banes 's post about this).

+34
Dec 29 '15 at 18:45
source share

Put the xml line below in your "AppTheme" xml, instead of trying to install it from "AppTheme.Button". This works for me on v22.1.1 with non-lollipop devices. I assume this is a mistake, because your solution above works fine for candy.

 <item name="colorButtonNormal">@color/my_color</item> 
+13
Apr 27 '15 at 16:42
source share

Using:

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

uninstall android:

+12
Sep 02 '15 at 21:58
source share

Make sure that your Activity extends AppCompatActivity , otherwise it will not correctly handle appCompat styles.

  • class: android.support.v7.app.AppCompatActivity
  • Gradle: compile 'com.android.support:appcompat-v7:23.0.1'
+12
04 Oct '15 at 18:42
source share

It works:

 <!-- 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</item> </style> <style name="MyCustomButton" parent="Base.Widget.AppCompat.Button"> <item name="android:textColor">#ffffff</item> <item name="android:textAppearance">?android:attr/textAppearanceMedium</item> </style> 

colorButtonNormal can be set in theme style. To change the text color, size, or any other function of a button, you can create a style, and then use buttonStyle (less than v21) or android:buttonStyle (v21 +) in a theme style to set the button style.

+8
May 2, '16 at 19:24
source share

v21 / styles.xml

  <style name="AppTheme.BlueButton" parent="Widget.AppCompat.Button.Colored"> <item name="android:colorButtonNormal">@color/blue</item> <item name="android:textColor">@color/text_white</item> </style> 

styles.xml

 <style name="AppTheme.BlueButton" parent="Widget.AppCompat.Button.Colored"> <item name="colorButtonNormal">@color/blue_tint</item> <item name="android:textColor">@color/text_white</item> </style> 

Initially, I also encounter this problem. After fixing as above, I got the right user interface button

+3
May 29 '17 at 9:03
source share

If you are wondering why colorButtonNormal not selected as defined for disabled buttons, you may also need to set android:disabledAlpha to 1.0 in the theme, otherwise your default color will mix with the background of the button. Example:

 <style name="MyButtonTheme" parent="ThemeOverlay.AppCompat.Light"> <item name="android:disabledAlpha">1.0</item> <item name="colorButtonNormal">@color/my_solid_disabled_color</item> <item name="colorAccent">@color/my_solid_accent_color</item> <item name="buttonStyle">@style/my_button_style</item> </style> 
+1
Dec 13 '17 at 15:00
source share

Hey. I think that the child widget you are using may be wrong, it must be android:Widget.Button for API version 21 or earlier, for later version 21 or higher you should use `android: Widget.Material.Button. Let them say that the default style should look lower.

 res/values/styles.xml <resources> <!-- Base application theme. --> <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> <item name="android:buttonStyle">@style/AppTheme.Button</item> </style> <style name="AppTheme.Button" parent="android:Widget.Button"> <item name="android:background">@color/my_color</item> <item name="android:textColor">@android:color/white</item> </style> </resources> 

For API version 21, the resource style file should look like (res / values-v21 / style.xml)

 <resources> <style name="AppTheme.Button" parent="android:Widget.Material.Button"> <item name="android:background">@color/my_color</item> <item name="android:textColor">@android:color/white</item> </style> </resources> 

Thanks, let me know if you have any questions.

0
Apr 25 '15 at 4:50
source share



All Articles