How to Create Borderless Colored Button in Android

If you have seen our tutorial on how to create a borderless button in android you will notice you can easily adopt it to a borderless colored button in android.

We are going to use a shape drawable and assign it to background property of android button.

The code is simple and easy to understand.

Using Shape Drawable

btn_borderless.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/colorAccent"/>
</shape>

activity_borderless.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/colorAccent"/>
</shape>

Using Button Style

<Button
        android:id="@+id/button3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@color/colorPrimary"
        style="?android:attr/borderlessButtonStyle"
        android:text="@string/borderless_button"
        android:padding="12dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

Any one of the options above will achieve borderless colored button in android.

android borderless button

 

Add a Comment