当前位置: 移动技术网 > 移动技术>移动开发>Android > android开发教程之switch控件使用示例

android开发教程之switch控件使用示例

2019年07月24日  | 移动技术网移动技术  | 我要评论

复制代码 代码如下:

<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();// 关闭蓝牙
}
}
});

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网