当前位置 博文首页 > ithome:android之switch控件的用法

    ithome:android之switch控件的用法

    作者:[db:作者] 时间:2021-07-05 13:00


    在做一个蓝牙开关时候,用到了switch,记一下用法,其实跟Button是几乎一样的.

    布局中:

    <Switch
            android:id="@+id/open"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textOff="蓝牙关闭中"
            android:textOn="蓝牙开启中" />
    

    java代码中

    open.setOnCheckedChangeListener(new OnCheckedChangeListener() {
    
    			@Override
    			public void onCheckedChanged(CompoundButton buttonView,
    					boolean isChecked) {
    				// TODO Auto-generated method stub
    				if (isChecked) {
    					mBluetoothAdapter.enable();//打开蓝牙
    				} else {
    					mBluetoothAdapter.disable();// 关闭蓝牙
    				}
    			}
    		});


    就是这样了,一看就明白了.

    作者:jason0539

    微博:http://weibo.com/2553717707

    博客:http://blog.csdn.net/jason0539(转载请说明出处)

    cs