系统默认的Switch开关
switch是开关按钮,它在选中与取消选中时可展现的界面元素比复选框丰富
XML属性:
textOn
:设置右侧开启时的文本
textOff
:设置左侧开启时的文本
track
:设置开关轨道的背景
thumb
:设置开关标识的图标
布局资源文件
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="5dp"
tools:context=".SwitchDefaultActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:layout_weight="1"
android:padding="5dp"
android:text="Switch开关:" />
<Switch
android:id="@+id/sw_status"