android开发教程之switch控件使用示例
内容摘要
复制代码 代码如下:<Switchandroid:id="@+id/open"android:layout_width="wrap_content"android:layout_height="wrap_content"android:textOff="蓝牙关闭中"android:textOn
文章正文
复制代码 代码如下:
<Switch
android:id="@+id/open"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textOff="蓝牙关闭中"
android:textOn="蓝牙开启中" />
复制代码 代码如下:
open.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
if (isChecked) {
mBluetoothAdapter.enable();//打开蓝牙
} else {
mBluetoothAdapter.disable();// 关闭蓝牙
}
}
});
代码注释