In Android, Checkbox is a very important UI component, and in Android, the form it displays is getting better and better, which means that some systems, such as checkbox below 4.0, are still not good-looking, or are not in line with the style of the software, so we need to customize this component.
Customizing this component is very simple, just add and modify the xml file.
Preparation
Prepare two pictures, one is the selected picture and the other is the unselected picture. This article takes the same as an example.
Set selection box
Create a new file custom_checkbox.xml under drawable
Copy the codeThe code is as follows:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:andro >
<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 customization
Set the button property value to the custom_checkbox defined above.
Copy the codeThe code is as follows:
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="@drawable/custom_checkbox"
/>
After customization is complete, run your program.