Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: How to align the CheckBox text in the bottom?

Basically what I want is to have is a checkbox with the icon and the text below to the icon, something like this:

 -------------------
|   CheckBox Icon   |
|                   |
|   CheckBox Text   |
|                   |
 -------------------

By default the icon is placed in the left and the text in the right, both of them at the same level. Below the layout I'm using:

<CheckBox
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Switch state"
    android:button="@drawable/my_custom_selector" />

Any idea about how can I achieve to have the icon on top and the text below the icon?. Thanks in advance :)

like image 587
Androider Avatar asked Nov 20 '14 02:11

Androider


3 Answers

I had the same problem and I have solved it using this:

android:button="@null"
android:drawableTop="?android:attr/listChoiceIndicatorMultiple"
like image 170
Nadun Priyankarage Avatar answered Nov 08 '22 16:11

Nadun Priyankarage


You can make the LinearLayout vertical and put the CheckBox (without text) on top and the text in a TextView below.

Finally make the LinearLayout clickable and check/uncheck programmatically.

like image 27
View Avatar answered Nov 08 '22 16:11

View


CheckedTextView + state list with checked and unchecked drawables:

<CheckedTextView
    android:drawableTop="@drawable/checkmark"
    android:checked="true"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Checked text"/>

@drawable/checkmark

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/unchecked" android:state_checked="false"></item>
<item android:drawable="@drawable/checked"></item></selector>

(checkmark.xml is simplified).

like image 7
IuriiO Avatar answered Nov 08 '22 15:11

IuriiO