Search code examples
androidandroid-studiobackgroundandroid-button

Button's backgroundTint doesn't change even though a color was specified


My goal is to create a button with rounded corners.

I have a button with this in its attributes android:background="@drawable/roundstyle", which is supposed to change the corners of the buttons to curve.

Here is my roundstyle.xml, the button in activity_main.xml and my colors.xml.

roundstyle.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
    <solid android:color="@color/our_lightGray" />
    <corners android:radius="25dp" />
</shape>

activity_main.xml

<Button
        android:id="@+id/currentstatusButton"
        android:layout_width="329dp"
        android:layout_height="98dp"
        android:background="@drawable/roundstyle"
        android:backgroundTint="@color/our_lightGray"
        android:text="Current Status"
        android:textColor="@color/black"
        tools:layout_editor_absoluteX="16dp"
        tools:layout_editor_absoluteY="460dp" />

colors.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="black">#FF000000</color>
    <color name="white">#FFFFFFFF</color>
    <color name="our_lightGray">#D9D9D9</color>
</resources>

However, even though my roundstyle.xml has the solid color attribute, and my button itself has the backgoundTint attribute, the backgroud color is still in its default mode. This is what it looks like right now.

I've been looking online on what ways can I fix this but to no avail.

I tried adding the backgroudTint attribute and solid color in my .xmls but the color is still in default.


Solution

  • Using MaterialButton and set app:cornerRadius, example:

    <com.google.android.material.button.MaterialButton
                    android:id="@+id/currentstatusButton"
                    android:layout_width="329dp"
                    android:layout_height="98dp"
                    android:backgroundTint="#D9D9D9"
                    android:text="Current Status"
                    android:textColor="@color/black"
                    app:cornerRadius="25dp"
                    tools:layout_editor_absoluteX="16dp"
                    tools:layout_editor_absoluteY="460dp" />
    

    Result like this: https://i.sstatic.net/nSYTa6BP.png