Android, CheckBox and RadioButton Custom Style

android checkbox and radiobutton custom styleYou might want to create your own CheckBox custom style, and RadioButton custom style in Android, for your applications.

This is how you can achieve it, in a few steps:
-Create Image Drawables for their two stater (checked/unchecked).
-Create selector for this two drawables. The sample content should be something like this:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
	<item android:state_checked="true" android:drawable="@drawable/unchecked" />
	<item android:state_checked="false" android:drawable="@drawable/checked" />
</selector>

-Add this selector as android:button attribute for CheckBox or RadioButton

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@drawable/background">

    <CheckBox
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:button="@drawable/checkbox_selector"
        android:text="Custom CheckBox" />

    <RadioButton
        android:id="@+id/radioButton1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:button="@drawable/checkbox_selector"
        android:text="Custom RadioButton" />

</LinearLayout>

You can download this code: download code

Leave a Reply

Your email address will not be published. Required fields are marked *