user3213494
user3213494

Reputation: 13

Android Checkbox text over button

I'm creating custom checbox with this style

<item android:drawable="@drawable/bt_pick_true" android:state_checked="true"></item>
<item android:drawable="@drawable/bt_pick_false" android:state_checked="false"></item>
<item android:drawable="@drawable/bt_pick_true"></item>

I want to have text on that checbox to be over te this images, not on right side.

I try to add gravity on checkbox but nothing happend.

    android:gravity="center_horizontal|center_vertical"

Upvotes: 1

Views: 1552

Answers (2)

Kristijan Drača
Kristijan Drača

Reputation: 614

set it as background

<CheckBox
    android:id="@+id/checkbox"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:button="@null"
    android:background="@drawable/cb_pick_style"
    android:gravity="center_horizontal|center_vertical"
    android:text="Text" />

Upvotes: 3

user543
user543

Reputation: 3633

Don't use android:button, use android:drawableLeft and give drawable_padding in negative. Like:

<CheckBox
    android:id="@+id/checkbox"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:button="@null"
    android:drawableLeft="@drawable/ur custom_selector_checkbox"
    android:drawablePadding="-20dp"
    android:text="one" />

Upvotes: 0

Related Questions