how do I override the default purple background color in android studio

Viewed 1471
<Button
    android:layout_width="0dp"
    android:layout_height="70dp"
    android:layout_weight="1"
    android:background="@color/btn"
    android:text="7"
    android:backgroundTint="@color/txt"
    android:textColor="@color/black"
    android:textSize="16dp"/>
  1. am trying to change the background color, but the color value i give it, its still come out purple
3 Answers

From colors.xml or styles.xml (themes)

Res -> values -> colors.xml

You can also extend or override themes however you like

You can remove that background attr. You can try this.

<Button
   android:layout_width="0dp"   
   android:layout_height="70dp"   
   android:layout_weight="1"
   android:text="7"
   android:backgroundTint="#9575CD"    
   android:textColor="@color/black"    
   android:textSize="16dp"/>  

With a Theme.MaterialComponents.* theme the default background color of the Button (which is replaced by a MaterialButton) is the colorPrimary defined in your app theme. The default value is the purple.

You can change this value in your app theme defined styles.xml o themes.xml

If you want to change this color only in the button you can use also the app:backgroundTint attribute removing the android:background attribute:

<Button
    app:backgroundTint="@color/..."/>
Related