In Android, a checkbox is a very important UI component, and in Android it shows more and more beautifully, which means that some systems For example 4.0 below, the checkbox is still not good-looking, or with the software style is not coordinated, we need to customize this component.
Customizing this component is simple, and simply adding changes to the XML file.
Preparatory work
Prepare two pictures, one is the selected picture, the other is the unselected picture. This paper takes checked.png and unchecked.png as examples.
Set Selection box
Create a new file under Drawable custom_checkbox.xml
Copy Code code as follows:
<?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/checked" ></item>
<item android:state_checked= "false" android:drawable= "@drawable/unchecked" ></item>
<item android:drawable= "@drawable/unchecked" ></item><!--the default one-->
</selector>
Apply a custom
Set the Button property value to the Custom_checkbox defined above.
Copy Code code as follows:
<checkbox
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:button= "@drawable/custom_checkbox"
/>
Custom finished, run up your program.