Open the source Checkbox.java file, we can see the following:
public class checkbox extends compoundbutton { public checkbox (Context context) { this (context, null); } Public checkbox (context context, attributeset attrs) { this (Context, attrs, com.android.internal.r.attr.checkboxstyle); } public checkbox (context context, attributeset attrs, Int defstyle) { super (context, attrs, Defstyle); }}
As you can see, the checkbox is inherited from Compoundbutton, and Compoundbutton:
Public abstract class Compoundbutton extends Button implements Checkable
is a subclass of button, so the checkbox is also a subclass of button. As can be seen from the above code, the checkbox is different from the addition of the attribute Checkboxstyle, we found in the source of the definition of the style is as follows:
<style name= "Widget.CompoundButton.CheckBox" > <item name= "android:background" > @android:d rawable/btn_ check_label_background</item> <item name= "Android:button" > @android:d rawable/btn_check</item> & Lt;/style>
<selector xmlns:android= "Http://schemas.android.com/apk/res/android" > <!- - enabled states --> <item android:state_checked= "true" android:state_window_focused= "false" android:state_enabled= "true" android:drawable= "@drawable/btn_check_on" /> <item Android:state_checked= "false" android:state_window_focused= "false" android:state_enabled= "true" android:drawable= "@drawable/btn_check_off" /> <item android:state _checked= "true" android:state_pressed= "true" Android:state_enabled= "TruE " android:drawable=" @drawable/btn_check_on_pressed " /> <item android:state_checked=" false " android:state_pressed=" True " android:state_enabled=" true " android:drawable= "@drawable/btn_check_off_pressed" /> <item android:state_checked= "true" android:state_focused= "true" android:state_enabled= "true" android:drawable= "@drawable/btn_check_on_selected" /> <item android:state_checked= "false" android:state_focused= "true" android:state_enabled= "true" android:drawable= "@drawable/btn_check_off_selected" /> <item android:state_ Checked= "false" android:state_enabled= "true" android:drawable= "@drawable/btn_check_off" /> <item android:state_checked= "true" android:state_enabled= "true" android:drawable= "@drawable/btn_check_on" /> <!-- disabled states --> <item android:state_checked= "true" android:state_window_ Focused= "false" android:drawable= "@drawable/btn_ Check_on_disable " /> <item android:state_checked=" false " android: State_window_focused= "false" &NBSP;&Nbsp; android:drawable= "@drawable/btn_check_off_disable" / > <item android:state_checked= "true" android:state_focused= "true" android:drawable= "@drawable/btn_check_on_disable_focused " /> <item android:state_checked=" false " android:state_focused=" True " android:drawable=" @drawable/btn_check_off_ Disable_focused " /> <item android:state_checked=" false " android: drawable= "@drawable/btn_check_off_disable" /> <item android:state_ Checked= "true" android:drawable= "@drawable/btn_check_on_disable" /></selector>
each item corresponds to the effect that the checkbox displays in a different selection state, and after understanding the contents of the file, we can design an aesthetically pleasing checkbox with our own needs. The RadioButton display is basically similar to a checkbox and can be modified in the same checkbox.