1 <LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"2 Android:layout_width= "Match_parent"3 Android:layout_height= "Match_parent"4 android:orientation= "vertical"5 android:padding= "10DP" >6 7 <CheckBox8 Android:id= "@+id/ck_system"9 Android:layout_width= "Match_parent"Ten Android:layout_height= "Wrap_content" One android:padding= "10DP" A android:checked= "false" - Android:text= "This is a checkbox for the system" - Android:textcolor= "#000000" the android:textsize= "17SP" /> - - <CheckBox - Android:id= "@+id/ck_custom" + Android:layout_width= "Match_parent" - Android:layout_height= "Wrap_content" + Android:button= "@drawable/checkbox_selector" A android:padding= "10DP" at android:checked= "false" - Android:text= "This checkbox has changed the icon" - Android:textcolor= "#000000" - android:textsize= "17SP" /> - - </LinearLayout>
Java
1 PackageCom.example.alimjan.hello_world;2 3 ImportAndroid.content.Context;4 Importandroid.content.Intent;5 ImportAndroid.os.Bundle;6 Importandroid.support.v7.app.AppCompatActivity;7 ImportAndroid.widget.CheckBox;8 ImportAndroid.widget.CompoundButton;9 Ten /** One * Created by Alimjan on 7/2/2017. A */ - - Public classClass_3_2_1extendsAppcompatactivityImplementsCompoundbutton.oncheckedchangelistener { the - @Override - protected voidonCreate (Bundle savedinstancestate) { - Super. OnCreate (savedinstancestate); + Setcontentview (r.layout.code_3_2_1); -CheckBox Ck_system =(CheckBox) Findviewbyid (r.id.ck_system); +CheckBox Ck_custom =(CheckBox) Findviewbyid (r.id.ck_custom); ACk_system.setoncheckedchangelistener ( This); atCk_custom.setoncheckedchangelistener ( This); - } - - @Override - Public voidOnCheckedChanged (Compoundbutton Buttonview,BooleanisChecked) { -String desc = String.Format ("You have%s this checkbox", isChecked?) Tick ":" To Uncheck "); in Buttonview.settext (DESC); - } to + Public Static voidstarthome (Context mcontext) { -Intent Intent =NewIntent (Mcontext, Class_3_2_1.class); the mcontext.startactivity (intent); * } $ Panax Notoginseng}
Android Development Note ___ check box __checkbox