Make a Round Button in Android

Create a Round or Oval shape Button in Android with XML

Those round or oval buttons in android apps look nice than the square buttons, and you can make one kinda easy by following this example

Advertisements

First, create an XML file in the Drawable folder (RIGHT CLICK  on drawable folder> NEW > DRAWABLE RESOURCE FILE).

Name it roundbutton.xml. Then add this XML code in it

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="false">
        <shape android:shape="rectangle">
            <corners android:radius="1000dp" />
            <solid android:color="#009688" />
            <padding
                android:bottom="4dp"
                android:left="4dp"
                android:right="4dp"
                android:top="4dp" />
        </shape>
    </item>
    <item android:state_pressed="true">
        <shape android:shape="rectangle">
            <corners android:radius="1000dp" />
            <solid android:color="#0A7166" />
            <stroke
                android:width="2dip"
                android:color="#0A7166" />
            <padding
                android:bottom="4dp"
                android:left="4dp"
                android:right="4dp"
                android:top="4dp" />
        </shape>
    </item>
</selector>

You can edit this XML file for different appearances of button, for example – change shape, color etc

Assigning Oval Shape to a Button in Android

Next step is assigning this XML file to a button, you can do it with the android:background=”@drawable/roundbutton” in the layout file, below is the screenshot

 

, ,

Post navigation

Comments

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