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 :)
I had the same problem and I have solved it using this:
android:button="@null"
android:drawableTop="?android:attr/listChoiceIndicatorMultiple"
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.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With