Toggle Buttons

    xiaoxiao2023-09-19  2

    Toggle button给用户提供两选一的方案,例如on/off。只允许用户选择其中的一个.你可以直接在layout文件中添加一个Toggle button。 Toggle button 同样也是CompoundButton的子类,可以调用CompoundButton.setCheck() 或者CompoundButton.toggle()来自己改变Toggle button的状态。 在activity中要检测用户的点击事件,可以重写CompoundButton。OncheckeckListener方法来检测toggle button 是enable还是disable. code 如下所示: ToggleButton toggle = (ToggleButton) findViewById(R.id.togglebutton); toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {     public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {         if (isChecked) {             // The toggle is enabled         } else {             // The toggle is disabled         }     } }); 先通过findViewById 找到ToggleButton,然后重写onCheckedChanged,通过形参的第二个参数boolean isChecked来判断togglebutton是enable还是disable.
    转载请注明原文地址: https://ju.6miu.com/read-1279109.html
    最新回复(0)