I'm trying to imitate the CheckBox
s like in the Settings app on my phone.
It looks like that:
I've tried using separate TextView
s, but that way only the checkmark is clickable, rather than the text and the checkmark.
Is there a way to accomplish that?
I also tried a CheckedTextView
but couldn't find the right drawable to use.
As far as I know this should work
<?xml version="1.0" encoding="utf-8"?>
<CheckBox xmlns:android="http://schemas.android.com/apk/res/android"
android:text="Text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:button="@null"
android:drawableRight="?android:attr/listChoiceIndicatorMultiple"/>
With android:button="@null"
you remove standard checkbox button / image, and after you just add checkbox image as right drawable (or use drawableEnd to support RTL)
android:drawableRight="?android:attr/listChoiceIndicatorMultiple"
Is there a way to accomplish that? I also tried a CheckedTextView but couldn't find the right drawable to use.
CheckedTextView will solve your issue perfectly:
Please look for example on simple_list_item_checked.xml (it is android embedded layout)
CheckedTextView have next attribute:
<!-- Drawable used for the check mark graphic. -->
<attr name="checkMark" format="reference"/>
So you only need to set checkMark to proper selector (If you do not have resource you could use btn_check.xml. It is inside android):
<CheckedTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checkMark="@drawable/your_selector_with_proper_checked_states"
/>
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