How to make Android CheckBox and RadioButton custom style
Anybody know that real cool Android application must have not only excelent business logic. The one of the most important things what application must have is a nice UI.
If you want to create realy interesting application you need to create good UI. And …. hire a designer 🙂
Below i want to tell you how to create your own CheckBoxes and RadioButtons for your Android Applications. Sorry for this sample UI design. I didn’t hire a designer :).
First look at screenshot:
Here you can see simple app with only one activity. Also below you can download the source code of Android project.
To make your own style for CheckBox or RadioButton you need to do next:
- Create Image Drawables for their two stater (checked/unchecked)
- Create selector for this two drawables. The sample content must be seem 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/star_down"></item> <item android:state_checked="false" android:drawable="@drawable/star"></item> </selector>
- Add this selector as android:button attribute for CheckBox or RadioButton
<CheckBox android:text="Custom CheckBox" android:button="@drawable/checkbox_selector" android:layout_width="wrap_content" android:layout_height="wrap_content">
That’s all. To make custom style for CheckBox and RadioButton you must do same steps.
Here you can download the Android project with the sample.