How to change Width of Android's Switch track?
Set your desired width of switch in the attribute:
android:switchMinWidth
for example:
<Switch
android:id="@+id/switchVisitAgain"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_margin="1dp"
android:checked="false"
android:gravity="center_vertical"
android:switchMinWidth="56dp"
android:textOff=""
android:textOn=""
android:thumb="@drawable/round_button"
android:track="@drawable/button_black" />
Here is my solution. I removed the texts, set the padding of the track and define the switchMinWidth
properties. This is my xml:
<Switch
android:id="@+id/theSwitchId"
android:textOn=""
android:textOff=""
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:thumbTextPadding="5dp"
android:switchMinWidth="40dp"
android:layout_gravity="right|center_vertical" />