9

How I can hide checkbox box only, but not checkbox text in . Checkbox is created programmatically.

myCheckBox.setVisibility(View.GONE) hides the whole checkbox with text also included. I would like to show only text but not box icon.

Looking forward to hear from you soon.

Lavekush Agrawal
  • 6,040
  • 7
  • 52
  • 85
anduplats
  • 885
  • 2
  • 14
  • 24
  • See also https://stackoverflow.com/questions/16063135/removing-the-box-from-the-checkbox-in-android. – CoolMind Nov 26 '19 at 08:50

2 Answers2

11

This works for me:

Drawable transparentDrawable = new ColorDrawable(Color.TRANSPARENT);
myCheckBox.setButtonDrawable(transparentDrawable);
okkko
  • 1,010
  • 1
  • 13
  • 22
-1

You can do like, don't give text value in checkbox element,you use separate textview for text and hide checkbox. Example

         <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Hindustan"/>
        <CheckBox
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:visibility="invisible"
            android:id="@+id/hindustanCB"/>