android之switch控件的用法

来源:互联网 发布:手机淘宝联盟 编辑:程序博客网 时间:2024/05/29 19:45

布局代码:

<Switch
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:id="@+id/sound_switch"/>


java代码:

                soundSwt = (Switch)findViewById(R.id.sound_switch);
        soundSwt.setChecked(MainActivity.soundSwitch);
        soundSwt.setOnCheckedChangeListener(new OnCheckedChangeListener(){


@Override
public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
// TODO Auto-generated method stub
if(arg1){
MainActivity.soundSwitch=true;
} else {
MainActivity.soundSwitch=false;
}
}
   
    });

    

0 0
原创粉丝点击