how to change text direction to the right slide of switch in android?

6.3k views Asked by At

In default mode , text of a Switch sit on the left side of ON/OFF states. I want to change direction of this text to the right slide. How can i do this?

I already try this xml code but not working:

<Switch
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/switch1"
android:layout_gravity:"right"
android:layout_margin="@dimen/abc_dropdownitem_text_padding_right"/>
3

There are 3 answers

0
Murtaza Khursheed Hussain On BEST ANSWER

AFAIK thats not doable, you can try the following

<RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <Switch
            android:id="@+id/switch_gprs"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:checked="false"
            android:paddingBottom="15dp"
            />

        <TextView

            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:checked="false"
            android:paddingBottom="15dp"
            android:layout_toRightOf="@+id/switch_gprs"
            android:text="sometext"/>


    </RelativeLayout>
0
Jéwôm' On

Or you can do :

<LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <Switch
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="My Switch"/>

</LinearLayout>
2
Ezequiel Messore On

You can use this:

android:layoutDirection="rtl"