ToggleButton与Switch都是开关按钮,ToggleButton出现在比较早的版本中,Switch是最近几个版本才出现的。个人感觉Switch比较好看一些。
ToggleButton的截图:
Paste_Image.png
Switch 的截图:
Paste_Image.png
<ToggleButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New ToggleButton"
android:id="@+id/toggleButton"
android:layout_below="@+id/radioGroup"
android:layout_alignParentStart="true" />
<Switch
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="200dp"
android:layout_marginTop="30dp"
android:id="@+id/switch0"
android:checked="true" />
另外,ToggleButton 与 Switch都需要实现各自的点击事件的处理,这里我就不多说了。