Rounded Button in Android Studio

Nidhi Vanjare
The Startup
Published in
Oct 3, 2020

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.

Drawable > New > Drawable Resource File (example: rounded_corner.xml)

Add this code :

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

Color and corner radius for the button can be modified as per your needs. The changes you make can be seen in the design option in the side:

Now , in the main xml file where you want the rounded corners for the button , add this line : android:background=”@drawable/rounded_corner ” .

<Button
android:id="@+id/btn_login"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginTop="20dip"
android:background="@drawable/rounded_corner"
android:text="@string/btn_login"
android:textSize="20dp"
android:textColor="@android:color/white"
/>

Thank You , Happy coding !

--

--