The switch height looks really small on a tablet. Is there a way, we can increase the height? If we increase it by giving a value to layout_height, it just add some blank space at the bottom, but the switch size doesnt increase.
Asked
Active
Viewed 1.2k times
3 Answers
5
you can try this:
android:thumbTextPadding="25dp"
android:switchMinWidth="56dp"
android:track="@drawable/custom_grey_image"
-
1
-
so you can use drawable and set it. android:thumb="@drawable/round_button" android:track="@drawable/button_black" – dipali Sep 16 '13 at 11:30
-
1
-
1as per my exp.,its only possible using only custome images.I have already find out all solutions. – dipali Sep 16 '13 at 12:12
-
1I just did some rnd and found that we actually dont need to use android:thumb. We can keep the default and just use android:track with some grey image of height say 50px – Gaurav Sep 16 '13 at 12:21
3
The @dipali answer is righthere is a small example how to change your swicth width, i hope it will help some one..
1)Use ur color for thumb (/res/drawable/color_thumb.xml)
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<size android:height="40dp" />
<gradient android:height="40dp" android:startColor="#FF569BDA" android:endColor="#FF569BDA"/>
2)gray color for track (/res/drawable/gray_track.xml)
shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"
>
<size android:height="40dp" />
<gradient android:height="40dp" android:startColor="#dadadada" android:endColor="#dadadada"/>
3)Selector for thumb (/res/drawable/thumb.xml)
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:drawable="@drawable/gray_track" />
<item android:state_pressed="true" android:drawable="@drawable/color_thumb" />
<item android:state_checked="true" android:drawable="@drawable/color_thumb" />
<item android:drawable="@drawable/gray_track" />
4) Selector for track (/res/drawable/track.xml)
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:drawable="@drawable/color_thumb" />
<item android:drawable="@drawable/gray_track" />
and finally in switch
use
android:switchMinWidth="56dp"
android:thumb="@drawable/thumb"
android:track="@drawable/track"
-
doesn't seem to work for SwitchMaterial. The switch got invisible after this update – Amir Dora. Feb 08 '21 at 11:16
-2
You can try to use android:padding="5dp"
or android:paddingTop="5dp" and android:paddingBottom="5dp"

Teo
- 3,143
- 2
- 29
- 59
-
Nope. That doesnt work! I want to increase size of the switch and not add padding or any margin. – Gaurav Sep 16 '13 at 11:23