1

I tried to change the background colors of buttons in an android project but it seems ineffective

This is the xml code of a button:

<Button
                android:id="@+id/comma"
                android:layout_width="0px"
                android:layout_height="90dp"
                android:layout_weight="9"
                android:background="@drawable/button_border"
                android:insetTop="0dp"
                android:insetBottom="0dp"
                android:text="."
                android:textColor="#7ff5f2"
                android:textSize="120px" />

My drawable resource file:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient android:startColor="092c32"
        android:centerColor="#026a6d"
        android:endColor="#092c32"
        android:angle="270" />
    <corners android:radius="3dp" />
    <stroke android:width="5px" android:color="#35f5f2" />
</shape>

This is my expected button background color in my drawable resource file

This is the app design

You can see the button background color above looks similar to the default purple, except there's a gradient, which I think related to the gradient in my drawable resource file.

Tam Nguyen
  • 25
  • 5
  • check https://stackoverflow.com/questions/64722733/android-background-drawable-not-working-in-button-since-android-studio-4-1 – CSmith May 20 '21 at 18:58

1 Answers1

2

This may solve the problem

 <androidx.appcompat.widget.AppCompatButton
        android:id="@+id/comma"
        android:layout_width="0px"
        android:layout_height="90dp"
        android:layout_weight="9"
        android:background="@drawable/button_border"
        android:insetTop="0dp"
        android:insetBottom="0dp"
        android:text="."
        android:textColor="#7ff5f2"
        android:textSize="120px" />
        />

Notice the change in the first line.

user14253444
  • 67
  • 1
  • 13