在
切换按钮上设置文本时的默认结果是右侧的拇指/轨道
+-------------+----------+
| | |
| Lorem Ispu | on / off |
| | |
+-------------+----------+
要知道是否有任何方法可以将thump/tacker放置在文本的左侧,而无需编写自定义小部件:
+-----------+-------------+
| | |
| on / off | Lorem Ipsum |
| | |
+-----------+-------------+
谢谢:)
我发现的唯一方法是将 Switch 和 TextView 包装在 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>
希望对您有所帮助。想法与此处提到的相同:如何在右侧显示android复选框?我只是颠倒了顺序。
要设置开关的默认值,您必须在 xml 中定义此代码
android:checked="true"