android – How to make a round button?

android – How to make a round button?

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.

android – How to make a round button?

  1. 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>
    
  2. Use it in button tag in any layout file

    <Button
        android_layout_width=220dp
        android_layout_height=220dp
        [email protected]/button_states
        [email protected]/btn_scan_qr
        [email protected]+id/btn_scan_qr
        android_textSize=15dp
    />
    

Leave a Reply

Your email address will not be published.