How to change the size of a Switch Widget

Janusz picture Janusz · Apr 16, 2012 · Viewed 90.7k times · Source

In Ice Cream Sandwich a Switch Widget was introduced that displays an On Off Slider.

I added the Switch like this:

<Switch 
    android:layout_width="fill_parent"
    android:layout_height="48dp"
    android:textStyle="bold"
    android:thumb="@drawable/switch_thumb_selector"
    android:track="@drawable/switch_bg_selector" />

The track and thumb drawables are nine patch images that should scale to all possible sizes. I hoped that the Switch would scale to the maximum size inside the given bounds, but it seems as if the drawables are just centered inside the supplied space.

Is it possible to increase the size of the Switch to make it appear bigger?

Answer

Gaurav picture Gaurav · Sep 22, 2016

Using scale property to change size worked for me.

Add these lines to your <switch/> tag in xml file.

android:scaleX="2"
android:scaleY="2"

You can change scale value as per your need. Here value 2 makes it double in size, similarly value 0.5 makes it half in size.

Example:

       <Switch
            android:id="@+id/switchOnOff"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:scaleX="2"
            android:scaleY="2"/>