Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Correct way to remove the box of checkbox completely in API 16 and lower

I've got a problem with hiding the box of my CheckBox. My CheckBox looks like this at the moment:

<CheckBox
    android:id="@+id/favoritesBox"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:button="@null"
    android:tag="1"
    android:textStyle="italic"
    android:text="@string/details_tags_favs" />

The only problem here is, the button=@null is removing its style and its not completely gone. Because of that, my text is not centered but moved to the right (by box size).

Is there a smooth way to get rid of it completely in API 16 and lower?

like image 270
JakubW Avatar asked Sep 01 '14 07:09

JakubW


1 Answers

With a little help from from Andrew T. with my RubberDuck debugging I found solution for this problem.

What you have to do is set background="@android:color/transparent on CheckBox and the invisible box will be gone from your View.

So my new CheckBox looks like this:

<CheckBox
    android:id="@+id/favoritesBox"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:button="@null"
    android:background="@android:color/transparent"
    android:tag="1"
    android:textStyle="italic"
    android:text="@string/details_tags_favs" />
like image 50
JakubW Avatar answered Oct 20 '22 21:10

JakubW