5

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.

Gaurav
  • 1,700
  • 4
  • 22
  • 38

3 Answers3

5

you can try this:

android:thumbTextPadding="25dp"
android:switchMinWidth="56dp"
android:track="@drawable/custom_grey_image"
Gaurav
  • 1,700
  • 4
  • 22
  • 38
dipali
  • 10,966
  • 5
  • 25
  • 51
  • 1
    It only increase the width but not the height. – Gaurav Sep 16 '13 at 11:25
  • 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
    So its only possible using a custom image? – Gaurav Sep 16 '13 at 12:09
  • 1
    as per my exp.,its only possible using only custome images.I have already find out all solutions. – dipali Sep 16 '13 at 12:12
  • 1
    I 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"
CAA
  • 968
  • 10
  • 27
Asthme
  • 5,163
  • 6
  • 47
  • 65
-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