Android:如何让CheckBox无法选择?

时间:2017-03-05 15:29:17

标签: android checkbox

在Android上,如何制作一个活动但不可选择的CheckBox?我想禁止用户更改选中未选中状态。

谢谢

1 个答案:

答案 0 :(得分:1)

  

在Android上,我如何制作一个活动的CheckBox但不是   可选择?我想禁止用户更改选中的不是   检查状态。

您可以将Checkbox子类化,并强制setChecked始终为true。 E.g。

public class AlwaysCheckedCheckBox extends AppCompatCheckBox {

    public AlwaysCheckedCheckBox(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public void setChecked(boolean checked) {
        super.setChecked(true);
    }
}

并将其引用到您的布局