1
<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 Answers3

3

From colors.xml or styles.xml (themes)

Res -> values -> colors.xml

You can also extend or override themes however you like

Poorix
  • 106
  • 7
1

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"/>  
Ticherhaz FreePalestine
  • 2,738
  • 4
  • 20
  • 46
0

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/..."/>
Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841