布局:
<ToggleButton
android:id="@+id/toggleBt"
android:layout_width="140.0dip"
android:layout_height="wrap_content"/>
use code:
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btnChangewifiStatus:
break;
case R.id.toggleBt:
//调用button监听器,每次点击toggleButton时,开启和关闭两个状态进行切换,可以在这两个状态切换的同时执行相应的操作
toggleBt.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
toggleBt.setChecked(isChecked);
if (isChecked) Log.d("oy", "toggleBt is Checked");
else Log.d("oy", "toggleBt is not checcked");
}
});
break;
}
}
标签:layout,Log,toggleBt,开关,isChecked,ToggleButton,按钮,android,id From: https://www.cnblogs.com/a-n-yan/p/17295967.html