Android Interpretation checkbox

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.