我想在代码中打开或关闭 SwitchCompat 小部件。我的意思是当用户将 SwitchCompat 从 On 更改为 Off 或其他时。我想在代码中做到这一点。我该怎么做?
SwitchCompat switchCompat = (SwitchCompat) findViewById(R.id.switch_compat);
最佳答案
与任何 CompoundButton
一样,您可以通过编程方式更改 SwitchCompat
的选中状态 via setChecked()
.
关于android - 如何在代码中打开或关闭 SwitchCompat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34961252/