How to Add Rounded Buttons in Android Studio

There is no default attribution to make a button round in Android Studio. So to do that we have to add a new XML file to make the button round.

So here i will help you add Rounded button in your project without the need of creating Shape.xml  file.

Step 1:Create a project named RoundedButton(or you can just add the code in the project ) in your Android Studio.

Step 2: Open your Gradle scripts and just add the below implementation code in build.gradle dependencies block and press on sync now.

 implementation ‘com.lai:buttonStyle:1.0.2’

Step 3: Open your Layout File and enter the below given code in it.

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<!--"enter the below code in your layout file"-->
<com.lai.library.ButtonStyle
android:id="@+id/buttonStyle"
android:layout_width="96dp"
android:layout_height="37dp"
android:layout_margin="5dp"
android:layout_marginTop="176dp"
android:text="Success"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.58"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:type="ok" />
<com.lai.library.ButtonStyle
android:id="@+id/activity_btn_1"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_marginTop="40dp"
android:text="@string/app_name"
app:type="warning"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.579"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/buttonStyle"
app:normal_color="#F1F1F1"
app:press_color="#E9EEF2"
app:stroke_color="#CCCDD0"
app:stroke_width="1dp" />
</androidx.constraintlayout.widget.ConstraintLayout>

Now your are ready to run the application!

Following are the attributes which you can use while implementing buttons in your project.

Attributeintroduce
type ok,info,warning,error
normal_colorDefault color
press_colorPress color
stroke_colorstroke color
stroke_widthtroke width
cornercorner size

The Output will be as shown in the below Image.

Screenshot_20210414-165217

Thank You For Visiting Our Website!

Source:  Android Developer: Buttons

Be Sure To Contribute In The Ocean of Knowledge and Ideas.

Please Visit : Activity Lifecycle – Code-Tech Community (codetech.tech)

And make sure to leave us a comment down below , we will be happy to know if this worked for you.

Happy Coding Mates! 🙂

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Shopping Cart