Removing a window from a checkbox in Android

I am an entry-level software developer and have found many great answers from this site, but I cannot find how to hide the checkbox “box” in Android. I just want the checkmark to appear when the user selects a parameter. Here are some of the last things I've tried.

chkSortOrder.setBackgroundResource (android.R.color.transparent); chkSortOrder.setBackgroundResource (android.R.drawable.checkbox_off_background);

Both of them still show a window.

+10
source share
3 answers

add the following attribute to your checkbox tag in XML.

Android: button = "@ android: color / transparent"

+32
source

, , - . RadioButton , :

checkbox.setButtonDrawable(null);
checkbox.setBackgroundResource(R.drawable.your_custom_drawable);
+2

I found this error when upgrading from androidx.appcompat: appcompat: 1.0.0 to 1.1.0.

None of the other answers were useful to me, since setting the button attribute to @null or @android: color / transparent does not work on the Android API level 20 or lower.

I changed my CheckBox to ToggleButton and assigned the textOn and textOff attributes an empty string

<ToggleButton
    ...
    android:background="@drawable/custom_selector"
    android:textOff=""
    android:textOn="" />

This way I can update the AndroidCompat application to version 1.1.0

0
source

All Articles