Wednesday, 23 July 2014

Android: Create Round Buttons

To make a button round we can first make a shape.xml in our drawable folder

shape.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >

    <stroke
        android:width="6dp"
        android:color="#FFFFFF" />

    <solid android:color="#FF66B2" />


    <corners
        android:bottomLeftRadius="45dp"
        android:bottomRightRadius="45dp"
        android:topLeftRadius="45dp"
        android:topRightRadius="45dp" />

</shape>

This shape can be used as a background of the button:

           <Button
                android:id="@+id/round1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/round_button"
                android:gravity="center" />

3 comments:

  1. You make shape.xml... but you are using round_button in this line :
    android:background="@drawable/round_button"
    Where is that round_button coming from...??

    ReplyDelete
  2. It should be "drawable/round1"

    ReplyDelete
  3. Worst explanation wasted my time.

    ReplyDelete