问题
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.
回答1:
you can try this:
android:thumbTextPadding="25dp"
android:switchMinWidth="56dp"
android:track="@drawable/custom_grey_image"
回答2:
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"
回答3:
You can try to use android:padding="5dp"
or android:paddingTop="5dp" and android:paddingBottom="5dp"
来源:https://stackoverflow.com/questions/18826136/android-is-there-a-way-to-change-the-height-of-switch-button