设置禁用时的背景复选框android



今天我用它工作,我得到一个问题。当我像这样设置复选框:

checkboxsend.setEnabled(false);

这里我想要的背景复选框不更改为禁用?我能做什么?请帮帮我!谢谢

 <CheckBox
    android:id="@+id/checkboxsend"
    android:focusable="false"
    android:focusableInTouchMode="false"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:checked="false"
    android:enabled="false" />

你会想要使用一个可绘制的状态作为复选框的背景,像这样的东西应该会让你更接近你的目标:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_enabled="false" android:state_checked="true" android:drawable="@android:drawable/checkbox_on_background"/>
    <item android:state_enabled="true" android:state_checked="true" android:drawable="@android:drawable/checkbox_on_background"/>
    <item android:drawable="@android:drawable/checkbox_off_background"/>
</selector>

你可以对它进行修改,以匹配你的确切逻辑。

你的复选框看起来像这样:

<CheckBox
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:enabled="false"
        android:background="@drawable/custom_checkbox"
        android:checked="true"/>

试试这个…如果您不想更改复选框的背景颜色,请使用....

:

checkboxsend.setEnabled(false);

使用:

checkboxsend.setClickable(false);