Switch and ToggleButton buttons are also often seen on mobile phones, such as WLAN, Bluetooth, GPS switches, etc. in the phone settings.
First, drag a switch and ToggleButton button on the tool,
Generate the XML code as follows:
1 <Relativelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"2 Xmlns:tools= "Http://schemas.android.com/tools"3 Android:layout_width= "Match_parent"4 Android:layout_height= "Match_parent"5 Android:paddingbottom= "@dimen/activity_vertical_margin"6 Android:paddingleft= "@dimen/activity_horizontal_margin"7 Android:paddingright= "@dimen/activity_horizontal_margin"8 Android:paddingtop= "@dimen/activity_vertical_margin"9 Tools:context= "Com.example.switchtogglebutton.MainActivity" >Ten One <TextView A Android:id= "@+id/textview1" - Android:layout_width= "Wrap_content" - Android:layout_height= "Wrap_content" the Android:text= "@string/hello_world" /> - - <Switch - Android:id= "@+id/switch1" + Android:layout_width= "Wrap_content" - Android:layout_height= "Wrap_content" + Android:layout_alignparentleft= "true" A Android:layout_below= "@+id/textview1" at Android:layout_margintop= "46DP" - Android:text= ' Switch switch ' /> - - <ToggleButton - Android:id= "@+id/togglebutton1" - Android:layout_width= "Wrap_content" in Android:layout_height= "Wrap_content" - Android:layout_alignleft= "@+id/switch1" to Android:layout_below= "@+id/switch1" + Android:layout_margintop= "36DP" - Android:text= "ToggleButton" /> the * </Relativelayout>
Run the display effect:
6.Android Switch and ToggleButton button learning