当前位置: 动力学知识库 > 问答 > 编程问答 >

xml - 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

<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" />

网友答案:

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

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

分享给朋友:
您可能感兴趣的文章:
随机阅读: