Customize the CheckBox style and checkbox Style
1. Custom
2. Prepare the selected and unselected images.
2.1 images and file names
Btn_check_off.png btn_check_on.png
2.2 Project Structure
3. Compile A Style File
3.1 project file structure
3.2 checkbox_style.xmlCode
<Selectorxmlns: android = "http://schemas.android.com/apk/res/android">
<Itemandroid: drawable = "@ drawable/btn_check_on" android: state_checked = "true"/>
<Itemandroid: drawable = "@ drawable/btn_check_off" android: state_checked = "false"/>
</Selector>
4.Compile page filesMain. xml
<CheckBox
Android: id = "@ + id/checkBox1"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: button = "@ drawable/checkbox_style"
Android: text = "CheckBox"/>
5. Status Change Events
CheckBox chk = (CheckBox) findViewById (R. id.CheckBox1);
Chk. setOnCheckedChangeListener (NewOnCheckedChangeListener (){
PublicVoidOnCheckedChanged(CompoundButton buttonView,BooleanIsChecked ){
Toast. makeText (CheckBoxActivity.This, "Selected status:" + (isChecked? "Selected": "Not selected"), Toast.LENGTH_SHORT). Show ();
}
});