Android CheckedTextView Checkbox on Left
Asked Answered
D

3

11

Just a quick simple question, I am using CheckedTextView and I was wondering what, if any, line of code I could use to place the check box on the left side instead of the right side.

Here is my current CheckedTextview Code:

<CheckedTextView
    android:id="@+id/ootChild"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="25dp"
    android:textSize="17sp"
    android:checkMark="@drawable/btn_check_off"
    android:clickable="true"
    android:checked="false" 
    android:onClick="toggle"/>

If there isn't an easy or quick way to do it I can always just use a CheckBox and TextView and place them how I want them.

Disparity answered 4/6, 2014 at 6:52 Comment(2)
#19229042Puduns
#3115245Puduns
C
27

Add android:drawableLeft="?android:attr/listChoiceIndicatorMultiple" as an XML attribute on your CheckedTextView. You can add android:drawableLeft="?android:attr/listChoiceIndicatorSingle" to see a radio instead of a checkbox.

Child answered 4/6, 2014 at 6:55 Comment(6)
Whoops! I did mean left side. Edited.Disparity
This won't support tinting and will fail on API <= 20. Check this: https://mcmap.net/q/395124/-how-do-i-make-the-checkbox-in-android-checkedtextview-be-left-aligned-instead-of-right-alignedIncommunicative
android:drawableLeft="?android:attr/listChoiceIndicatorMultiple" shows Checkbox on the left instead of showing drawable set by checkMark on the left.Hoicks
love u bruuuuhhhhhhhhhhhhh u saved my time :DLinville
I tried this on a CheckedTextView used for a single selection list and I get a checkbox on the left and a radio-style round marker on the right.Server
A bit late, but there is no radio appearance answer here.. You can use below declaration to see a radio instead checkbox.. android:drawableLeft="?android:attr/listChoiceIndicatorSingle"Upthrust
I
0

Add android:layoutDirection="rtl" So the code in the question becomes:

<CheckedTextView
android:id="@+id/ootChild"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:textSize="17sp"
android:checkMark="@drawable/btn_check_off"
android:clickable="true"
android:checked="false"
android:layoutDirection="rtl" 
android:onClick="toggle"/>
Insole answered 23/7, 2023 at 22:26 Comment(1)
Answer needs supporting information Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Coopt
N
-1

Use the following syntax:

<CheckedTextView
    android:id="@+id/ootChild"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="25dp"
    android:textSize="17sp"
    android:checkMark="@drawable/btn_check_off"
    android:clickable="true"
    android:checked="false"
    android:onClick="toggle"
    android:drawableLeft="?android:attr/listChoiceIndicatorMultiple" />
Northing answered 4/6, 2014 at 7:1 Comment(3)
I was using the @drawable/btn_check_off for my (current) CheckBox style.Disparity
@Mowza2k2: Sorry I removed it while testing the code since I don't have that resource. Now it's added :)Slavism
With this solution it will show drawable on both sides(left and right)Kuehnel

© 2022 - 2024 — McMap. All rights reserved.