border background is getting solid color when applying to a background button

Viewed 52

I have created a rectangle with a border rectangle_border.XML and no solid color.

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">

<corners android:radius="50dp" />

<size
    android:width="50dp"
    android:height="20dp" />

<stroke
    android:width="2dp"
    android:color="@color/White_Flight" />

and I have a button in which I set the background to rectangle_border:

            <com.google.android.material.button.MaterialButton
                android:id="@+id/loginPage"
                android:layout_width="87dp"
                android:layout_height="27dp"
                android:layout_marginBottom="10dp"
                android:background="@drawable/rectangle_border"
                android:text="@string/login"
                android:textColor="@color/dark_blue"
                android:textSize="8sp"
                app:backgroundTint="@color/White_Flight"
                app:layout_constraintBottom_toBottomOf="@id/home_background"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toLeftOf="@id/registerPage" />

the problem is the button is getting a solid color.

Here is the button:
here is the button

and here is the rectangle_border:
and here is the rectangle_border

1 Answers

I have made few changes to your background drawable and ImageView attributes

Add solid transparent color to drawable and remove size, you don't need it.

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

    <solid android:color="#00ffffff"/>

    <stroke
        android:width="2dp"
        android:color="@color/black" />
</shape>

I have removed backgroundTint attribute

 <com.google.android.material.button.MaterialButton
        android:id="@+id/loginPage"
        android:layout_width="87dp"
        android:layout_height="27dp"
        android:layout_marginBottom="10dp"
        android:background="@drawable/rectangle_border"
        android:text="@string/login"
        android:textColor="@color/dark_blue"
        android:textSize="8sp"
        app:layout_constraintBottom_toBottomOf="@id/home_background"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toLeftOf="@id/registerPage" />

Let me know if this worked for you.

Related