vendredi 7 octobre 2016

Create a rounded checkbox with boarder

This is how I create a rounded checkbox with boarder. But the boarder is in square shape,not circle.

CheckBox

<CheckBox
            android:id="@+id/checkBox"
            android:paddingTop="15dp"
            android:paddingRight="25dp"
            android:layout_width="25dp"
            android:layout_marginLeft="320dp"
            android:layout_height="25dp"
            android:button="@drawable/xml_button"
            android:background="@drawable/xml_background"/>

xml_button

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://ift.tt/nIICcg">
    <item android:state_checked="true">
        <shape android:shape="oval">
            <solid android:color="#00FF00" />
            <size
                android:width="24dp"
                android:height="24dp" />
        </shape>
    </item>
    <item android:state_checked="false">
        <shape android:shape="oval">
            <solid android:color="#AAA" />
            <size
                android:width="24dp"
                android:height="24dp" />
        </shape>
    </item>
</selector>

xml_background

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://ift.tt/nIICcg">
    <corners android:radius="3dp" />
    <stroke
        android:width="2dp"
        android:color="#CCC" />
    <padding
        android:left="34dp"
        android:top="5dp"
        android:right="10dp"
        android:bottom="5dp" />
</shape>

Output

enter image description here

Any help would be greatly appreciated. Thanks.




Aucun commentaire:

Enregistrer un commentaire