Switch開關控件.
1.XML文件:
<!--textOff:關閉狀態顯示的文字-->
<!--textOn:開啓狀態顯示的文字-->
<Switch
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/sc_main_swi"
android:textOn="關"
android:textOff="開"
/>
2.代碼:
sw_main_swi = (Switch) findViewById(R.id.sc_main_swi);
//給ToggleButton設置監聽事件
sw_main_swi.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked){
//開啓狀態
}else{
//關閉狀態
}
}
});
<!--textOff:關閉狀態顯示的文字-->
<!--textOn:開啓狀態顯示的文字-->
<Switch
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/sc_main_swi"
android:textOn="關"
android:textOff="開"
/>
2.代碼:
sw_main_swi = (Switch) findViewById(R.id.sc_main_swi);
//給ToggleButton設置監聽事件
sw_main_swi.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked){
//開啓狀態
}else{
//關閉狀態
}
}
});
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.