<?xml version= "1.0" encoding= "Utf-8"? ><manifest xmlns:android= "Http://schemas.android.com/apk/res/android" Package= "Com.hanqi.test5" > <Application Android:allowbackup= "true"Android:icon= "@mipmap/ic_launcher"Android:label= "@string/app_name"Android:supportsrtl= "true"Android:theme= "@style/apptheme" > <activity android:name= ". UIActivity1 "> <intent-filter> <action android:name=" Android.intent.action.MAIN "/> ; <category android:name= "Android.intent.category.LAUNCHER"/> </intent-filter> </activity& Gt <activity android:name= ". Longclickactivityactivity "> <intent-filter> <action android:name=" android.intent.act Ion. MAIN "/> <category android:name=" Android.intent.category.LAUNCHER "/> </intent-filte r> </activity> <activity android:name= ". Calculatoractivity "> <intent-filter> <action android:name=" Android.intent.action.MAI N "/> <category android:name=" Android.intent.category.LAUNCHER "/> </INTENT-FILTER&G T </activity> <activity android:name= ". Mainactivity "> <intent-filter> <action android:name= "Android.intent.action.MAIN"/> < Category android:name= "Android.intent.category.LAUNCHER"/> </intent-filter> </activity> <activity android:name= ". Activity1 "/> </application></manifest>
Of course, every time you have to register first, this is absolutely not forgotten, the second step is to write Java code
PackageCom.hanqi.test5;ImportAndroid.os.Bundle;Importandroid.support.annotation.IdRes;Importandroid.support.v7.app.AppCompatActivity;ImportAndroid.widget.CheckBox;ImportAndroid.widget.CompoundButton;ImportAndroid.widget.ImageView;ImportAndroid.widget.RadioButton;ImportAndroid.widget.RadioGroup;ImportAndroid.widget.Switch;ImportAndroid.widget.Toast;ImportAndroid.widget.ToggleButton; Public classUIActivity1extendsappcompatactivity {ImageView IV; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.LAYOUT.ACTIVITY_UI1); //Radio BoxRadiogroup Radiogroup =(Radiogroup) Findviewbyid (R.ID.RG); Radiogroup.setoncheckedchangelistener (NewRadiogroup.oncheckedchangelistener () { Public voidOnCheckedChanged (Radiogroup Group, @IdResintCheckedid) { if(Checkedid = = R.ID.RB3)//Rb3 Set as the correct answer{toast.maketext (UIActivity1). This, "the right choice.", Toast.length_long). Show (); } RadioButton RB=(RadioButton) Findviewbyid (Checkedid); Toast.maketext (UIActivity1. This, Rb.gettext (), Toast.length_long). Show (); } }); //check boxCheckBox Cb_st =(CheckBox) Findviewbyid (R.id.cb_st); Cb_st.setoncheckedchangelistener (NewCboncheckedchanglistenter () {@Override Public voidOnCheckedChanged (Compoundbutton Buttonview,BooleanisChecked) { } }); Cb_st.setoncheckedchangelistener (NewCboncheckedchanglistenter ()); CheckBox CB_JC=(CheckBox) Findviewbyid (R.ID.CB_JC); Cb_jc.setoncheckedchangelistener (NewCboncheckedchanglistenter ()); CheckBox Cb_xt=(CheckBox) Findviewbyid (R.ID.CB_XT); Cb_xt.setoncheckedchangelistener (NewCboncheckedchanglistenter ()); CheckBox Cb_xhx=(CheckBox) Findviewbyid (R.ID.CB_XHX); Cb_xhx.setoncheckedchangelistener (NewCboncheckedchanglistenter ()); IV=(ImageView) Findviewbyid (R.ID.IV); ToggleButton Tob=(ToggleButton) Findviewbyid (R.id.tob); Tob.setoncheckedchangelistener (NewToncheckedchangelistenter ()); Switch SW=(Switch) Findviewbyid (R.ID.SW); Sw.setoncheckedchangelistener (NewToncheckedchangelistenter ()); } Private classToncheckedchangelistenterImplementscompoundbutton.oncheckedchangelistener{ Public voidOnCheckedChanged (Compoundbutton Buttonview,BooleanisChecked) { if(isChecked) {iv.setimageresource (R.drawable.on); } Else{iv.setimageresource (R.drawable.off); } } } Private classCboncheckedchanglistenterImplementsCompoundbutton.oncheckedchangelistener {@Override Public voidOnCheckedChanged (Compoundbutton Buttonview,BooleanisChecked) {CheckBox CB=(CheckBox) Buttonview; if(isChecked) {toast.maketext (UIActivity1. This, "checked" +Cb.gettext (), Toast.length_long). Show (); } Else{toast.maketext (UIActivity1). This, "Canceled" +Cb.gettext (), Toast.length_long). Show (); } } }}
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:padding= "10DP"android:orientation= "Vertical"Tools:context= "Com.hanqi.test5.UIActivity1" > <TextView android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Please select what is the Android development language?" "/> <Radiogroup android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"android:orientation= "Horizontal"Android:id= "@+id/rg" > <RadioButton android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "C + +"Android:id= "@+id/rb1"Android:layout_marginright= "30DP"android:checked= "true"/> <RadioButton android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "C"Android:id= "@+id/rb2"Android:layout_marginright= "30DP"/> <RadioButton android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "JAVA"Android:id= "@+id/rb3"Android:layout_marginright= "30DP"/> <RadioButton android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "C #"Android:id= "@+id/rb4"/> </RadioGroup> <TextView android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Please select font effect"/> <CheckBox android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Song Body"Android:id= "@+id/cb_st"android:checked= "true"/> <CheckBox android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Bold"Android:id= "@+id/cb_jc"/> <CheckBox android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Italic"Android:id= "@+id/cb_xt"/> <CheckBox android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Underline"Android:id= "@+id/cb_xhx"/> <ImageView android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"android:src= "@drawable/off"Android:id= "@+id/iv"/> <ToggleButton android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:texton= "Open"Android:textoff= "Off"Android:id= "@+id/tob"/> <Switch android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Switch"Android:textoff= "Off"Android:texton= "Open"Android:id= "@+id/sw"/> <ToggleButton android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:texton=""Android:textoff=""Android:background= "@drawable/mybutton"Android:id= "@+id/tob1"/></linearlayout>
In particular, how can I let the button not display the font and use two background images to show the effect? This is going to use a piece of XML code, ******** this piece of code must be the name of all lowercase
<?xml version= "1.0" encoding= "Utf-8"? ><selector xmlns:android= "http://schemas.android.com/apk/res/ Android "> <item android:drawable=" @drawable/on "android:state_checked=" true "/> <item android: drawable= "@drawable/off" android:state_checked= "false"/></selector>
Implementation results:
Android Course---View widget switch button