1.xml文件
<Switch
android:id="@+id/notificate_sw"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="5dp"
android:checked="true"//设置默认打开switch
android:text="Set Notification"/>
2.设定基本属性
sw_noficate = (Switch) findViewById(R.id.notificate_sw);
sw_noficate.setTextOff("打开状态栏通知");
sw_noficate.setTextOn("关闭状态栏通知");
3.监听事件
sw_noficate.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
// TODO Auto-generated method stub
}
});