How to make a round button?
Create a drawable/button_states.xml file containing:
<?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="#41ba7a" /> <stroke android:width="2dip" android:color="#03ae3c" /> <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="#3AA76D" /> <stroke android:width="2dip" android:color="#03ae3c" /> <padding android:bottom="4dp" android:left="4dp" android:right="4dp" android:top="4dp" /> </shape> </item> </selector>
Use it in button tag in any layout file
<Button android:layout_width="220dp" android:layout_height="220dp" android:background="@drawable/button_states" android:text="@string/btn_scan_qr" android:id="@+id/btn_scan_qr" android:textSize="15dp" />
Create an xml file named roundedbutton.xml
in drawable folder
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#eeffffff" />
<corners android:bottomRightRadius="8dp"
android:bottomLeftRadius="8dp"
android:topRightRadius="8dp"
android:topLeftRadius="8dp"/>
</shape>
Finally set that as background to your Button
as android:background = "@drawable/roundedbutton"
If you want to make it completely rounded, alter the radius and settle for something that is ok for you.
If using Android Studio you can just use:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="#FFFFFF"/>
</shape>
this works fine for me, hope this helps someone.