Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display Switch behind the thumb android studio

Here is my current code it appear the text in thumb, but what I want is to display text behind in the the box like demo

enter image description here

<Switch
        android:layout_width="75dp"
        android:layout_height="25dp"
        android:id="@+id/switch1"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true"
        android:track="@drawable/switch_track_selector"
        android:showText="true"
        android:textOff="Hide"
        android:textOn="Show"
        android:switchMinWidth="75dp"
        android:thumb="@drawable/switch_thumb_selector" />
like image 352
Preap San Avatar asked Dec 06 '25 21:12

Preap San


1 Answers

For that you have to use either https://github.com/pellucide/Android-Switch-Demo-pre-4.0

enter image description here

OR

you can do something like Text is not shown by default under Material theme since the switch widget assets don't work well with text.

You can change this using the android:showText property or Switch.setShowText(boolean) method.

xml

 <Switch
        ...
        android:showText="true" />

programatically

mSwitch.setShowText(true);

please check https://developer.android.com/reference/android/widget/Switch.html#setShowText%28boolean%29

like image 131
Amit Vaghela Avatar answered Dec 08 '25 14:12

Amit Vaghela