Yathavan Seyavan
Yathavan Seyavan

Reputation: 25

Button Border Not Showing

I try to put a border for a button in android but unfortunately I can't see the button border.

Drawable File 👇

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <corners android:radius="12dp" />
            <stroke android:width="3px" android:color="#7E8082" />
        </shape>
    </item>
</selector>

XML 👇

<Button
        android:id="@+id/btn_signup"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:layout_marginTop="122dp"
        android:background="@drawable/bg_signup"
        android:fontFamily="@font/poppins_semibold"
        android:text="Create an Account"
        android:textAllCaps="false"
        android:textColor="@color/black"
        app:layout_constraintTop_toBottomOf="@+id/btn_login" />

I want this button

Upvotes: 2

Views: 2020

Answers (3)

Gabriele Mariotti
Gabriele Mariotti

Reputation: 363537

You don't need to use a custom drawable, just use a MaterialButton:

       <com.google.android.material.button.MaterialButton
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           style="@style/Widget.MaterialComponents.Button.OutlinedButton"
           app:strokeColor="#7E8082"
           app:strokeWidth="1dp"
           app:cornerRadius="12dp"/>

enter image description here

Upvotes: 2

Gias Uddin
Gias Uddin

Reputation: 1

use Style attribute instead of android:background="@drawable/bg_signup"

make a custom style then call it android:style="@style/bg_signup"

Upvotes: -1

HussainAbbas
HussainAbbas

Reputation: 262

Don't use a selector for single option use shape directly

bg_signup

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="#cdcdcd"/>
    <corners
        android:radius="4dp"
    />
    <stroke
        android:width="1dp"
        android:color="#000"
    />
</shape>

Upvotes: 0

Related Questions