4

The default result when setting up a text on a switch button is the thumb/track on the right

+-------------+----------+
|             |          |
|  Lorem Ispu | on / off |
|             |          |
+-------------+----------+

What is to know if there is any way to make the thump/tacker being placed on the left side of the text without having to write a custom widget:

+-----------+-------------+
|           |             |
|  on / off | Lorem Ipsum |
|           |             |
+-----------+-------------+

Thanks :)

Ramon Moraes
  • 477
  • 7
  • 23

2 Answers2

2

The only way I found is to have Switch and TextView wrapped in LinearLayout:

    <LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal">
    <android.support.v7.widget.SwitchCompat
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:checked="true"
        />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Your text:"/>
</LinearLayout>

Hope it helps. Idea was the same as mentioned here: How to show android checkbox at right side? I just reversed the order.

Community
  • 1
  • 1
vasiljevski
  • 369
  • 5
  • 9
-2

To set default value of switch you have to define this code in xml

android:checked="true" 
Anjali
  • 1
  • 1
  • 13
  • 20