Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Button background color not changing

Tags:

android

In this android project im creating a default button style. my styles.xml

<!-- Base application theme. --> <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">     <item name="android:buttonStyle">@style/ButtonStlye123</item> </style>  <style name="ButtonStlye123" parent="android:style/Widget.Button">     <item name="android:textSize">19dp</item>     <item name="android:layout_margin">8dp</item>     <item name="android:padding">8dp</item>     <item name="android:textColor">@color/ColorDivider</item>      <item name="android:background">@color/ColorAccent</item> </style> 

my button in a fragment.

<Button     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:text="@string/btnLogin"     android:id="@+id/btn_login"     android:layout_alignParentBottom="true"     android:layout_alignParentLeft="true"     android:layout_alignParentStart="true"     android:layout_alignParentRight="true"     android:layout_alignParentEnd="true"     android:theme="@style/ButtonStlye123"     android:onClick="login" /> 

In the preview in android studio it looks exactly like I want, but when I run the app on my device the background color is gray ("default button color"). If i change the text color in my styles.xml like:

<item name="android:textColor">@color/ColorPrimary</item> 

it changes (also on my device) so the custom style is loading, i tryd different colors (that worked for the text) for the button but it wont change.

Why isnt my background color loading?

like image 473
Sven van den Boogaart Avatar asked Aug 06 '15 14:08

Sven van den Boogaart


People also ask

How can change background color of button in Android?

To set Android Button background color, we can assign android:backgroundTint XML attribute for Button in layout file with the required Color Value. To programmatically set or change Android Button background color, we may call pass the method Button.

How do I change my toolbar color on android?

Just go to res/values/styles.edit the xml file to change the color of action bar. Code for styles.

How can I make my Android button more attractive?

Using colors (background, text, border) Using custom shapes like circle, rounded corners and more. You can add images to your buttons to customize them. Using drawables to make gradients, dotted borders and more.


1 Answers

Try use AppCompactButton instead of

<Button 

use

<androidx.appcompat.widget.AppCompatButton 

that will do the trick

Update: 01/06/2021

Found out that the above will not work on earlier Android versions. For materiel design Button use

app:backgroundTint="@color/green" 
like image 180
Hezy Ziv Avatar answered Sep 28 '22 08:09

Hezy Ziv