adirk1
adirk1

Reputation: 219

Why button is displaying the wrong color?

This button is displaying a purple color and its XML code is

enter image description here

        android:id="@+id/btnLogin"
        android:layout_width="128dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="141dp"
        android:layout_marginEnd="142dp"
        android:layout_marginBottom="48dp"
        android:background="@drawable/btn_login"
        android:fontFamily="@font/poppins"
        android:text="Login"
        android:textAllCaps="false"
        android:textSize="18sp"
        app:layout_constraintBottom_toTopOf="@+id/tvCreateAccount"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent" />

"@drawable/btn_login" is a shape I created -

<shape xmlns:android="http://schemas.android.com/apk/res/android"

    android:shape="rectangle">


    <solid android:color="#71D775">
    </solid>
    <corners android:radius="66dp">
    </corners>



</shape>

And this is how it looks like, just a light green arounded rectangle

Upvotes: 2

Views: 862

Answers (2)

skafle
skafle

Reputation: 1045

This is because the default MaterialButton style overrides backgroundTint.

So if we are using a custom android:background, we have to make sure to null out backgroundTint. We can achieve it by any of the following way:

Add any of these line to your button XML.

app:backgroundTint="@null"      

OR

app:backgroundTint="@empty"

Upvotes: 4

Tuvel
Tuvel

Reputation: 104

For some reason, you need to set the app:backgroundTint to null. Like so:

app:backgroundTint="@null"

Upvotes: 1

Related Questions