Can not apply shape to button

Viewed 1438

i have a strange issue. I created a simple Button which looks like that :

<com.google.android.material.button.MaterialButton
android:id="@+id/continue_button"
android:background="@drawable/green_button_selector"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/landing_margin"
android:layout_marginEnd="@dimen/landing_margin"
android:layout_marginBottom="@dimen/landing_margin"
android:text="@string/login_button_text"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />

I want to make Button green with rounded corners, so I created a xml file called green_button_selector and set is as button background. This file code's is posted below

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

But instead of my button getting green it has colorAccent of my app, any ideas what am I doing wrong?

2 Answers

If you are using material button you don't need to create custom drawable.

<com.google.android.material.button.MaterialButton
    style="@style/Widget.MaterialComponents.Button"
    android:textAppearance="@style/TextAppearance.AppCompat.Small"
    app:backgroundTint="@android:color/holo_green_dark"
    app:cornerRadius="10dp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    tools:text="BUTTON" />

enter image description here

More: https://material.io/develop/android/components/material-button/

<com.google.android.material.button.MaterialButton
android:id="@+id/material_text_button"
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/outlined_button_label_enabled"/>

You can below property for same.

app:cornerRadius app:backgroundTint

Read more from Material Button official document

Related