# MaterialSwitch

[View Source](https://github.com/material-components/material-components-android/blob/1.14.0/lib/java/com/google/android/material/materialswitch/MaterialSwitch.java)

*** ** * ** ***


```
public class MaterialSwitch
```

<br />

*** ** * ** ***

A class that creates a Material Themed Switch. This class is intended to provide a brand new Switch design and replace the obsolete `https://developer.android.com/reference/com/google/android/material/switchmaterial/SwitchMaterial` class.

For more information, see the [component developer guidance](https://github.com/material-components/material-components-android/blob/master/docs/components/Switch.md) and [design guidelines](https://material.io/components/switch/overview).

## Summary

| ### Public fields |
|---|---|
| `Drawable` | `https://developer.android.com/reference/com/google/android/material/materialswitch/MaterialSwitch#thumbDrawable()` |
| `Drawable` | `https://developer.android.com/reference/com/google/android/material/materialswitch/MaterialSwitch#thumbIconDrawable()` |
| `int` | `https://developer.android.com/reference/com/google/android/material/materialswitch/MaterialSwitch#thumbIconSize()` |
| `ColorStateList` | `https://developer.android.com/reference/com/google/android/material/materialswitch/MaterialSwitch#thumbIconTintList()` |
| `Mode` | `https://developer.android.com/reference/com/google/android/material/materialswitch/MaterialSwitch#thumbIconTintMode()` |
| `ColorStateList` | `https://developer.android.com/reference/com/google/android/material/materialswitch/MaterialSwitch#thumbTintList()` |
| `Drawable` | `https://developer.android.com/reference/com/google/android/material/materialswitch/MaterialSwitch#trackDecorationDrawable()` |
| `ColorStateList` | `https://developer.android.com/reference/com/google/android/material/materialswitch/MaterialSwitch#trackDecorationTintList()` |
| `Mode` | `https://developer.android.com/reference/com/google/android/material/materialswitch/MaterialSwitch#trackDecorationTintMode()` |
| `Drawable` | `https://developer.android.com/reference/com/google/android/material/materialswitch/MaterialSwitch#trackDrawable()` |
| `ColorStateList` | `https://developer.android.com/reference/com/google/android/material/materialswitch/MaterialSwitch#trackTintList()` |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/com/google/android/material/materialswitch/MaterialSwitch#MaterialSwitch(Context)(Context context)` |
| `https://developer.android.com/reference/com/google/android/material/materialswitch/MaterialSwitch#MaterialSwitch(Context,AttributeSet)(Context context, AttributeSet attrs)` |
| `https://developer.android.com/reference/com/google/android/material/materialswitch/MaterialSwitch#MaterialSwitch(Context,AttributeSet,int)(Context context, AttributeSet attrs, int defStyleAttr)` |

| ### Public methods |
|---|---|
| `Drawable` | `https://developer.android.com/reference/com/google/android/material/materialswitch/MaterialSwitch#getThumbDrawable()()` |
| `Drawable` | `https://developer.android.com/reference/com/google/android/material/materialswitch/MaterialSwitch#getThumbIconDrawable()()` Gets the drawable used for the thumb icon that will be drawn upon the thumb. |
| `int` | `https://developer.android.com/reference/com/google/android/material/materialswitch/MaterialSwitch#getThumbIconSize()()` Returns the size of the thumb icon. |
| `ColorStateList` | `https://developer.android.com/reference/com/google/android/material/materialswitch/MaterialSwitch#getThumbIconTintList()()` Returns the tint applied to the thumb icon drawable |
| `Mode` | `https://developer.android.com/reference/com/google/android/material/materialswitch/MaterialSwitch#getThumbIconTintMode()()` Returns the blending mode used to apply the tint to the thumb icon drawable |
| `ColorStateList` | `https://developer.android.com/reference/com/google/android/material/materialswitch/MaterialSwitch#getThumbTintList()()` |
| `Drawable` | `https://developer.android.com/reference/com/google/android/material/materialswitch/MaterialSwitch#getTrackDecorationDrawable()()` Get the drawable used for the track decoration that will be drawn upon the track. |
| `ColorStateList` | `https://developer.android.com/reference/com/google/android/material/materialswitch/MaterialSwitch#getTrackDecorationTintList()()` Returns the tint applied to the track decoration drawable |
| `Mode` | `https://developer.android.com/reference/com/google/android/material/materialswitch/MaterialSwitch#getTrackDecorationTintMode()()` Returns the blending mode used to apply the tint to the track decoration drawable |
| `Drawable` | `https://developer.android.com/reference/com/google/android/material/materialswitch/MaterialSwitch#getTrackDrawable()()` |
| `ColorStateList` | `https://developer.android.com/reference/com/google/android/material/materialswitch/MaterialSwitch#getTrackTintList()()` |
| `void` | `https://developer.android.com/reference/com/google/android/material/materialswitch/MaterialSwitch#invalidate()()` |
| `void` | `https://developer.android.com/reference/com/google/android/material/materialswitch/MaterialSwitch#setThumbDrawable(Drawable)(Drawable drawable)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/materialswitch/MaterialSwitch#setThumbIconDrawable(Drawable)(Drawable icon)` Sets the drawable used for the thumb icon that will be drawn upon the thumb. |
| `void` | `https://developer.android.com/reference/com/google/android/material/materialswitch/MaterialSwitch#setThumbIconResource(int)(int resId)` Sets the drawable used for the thumb icon that will be drawn upon the thumb. |
| `void` | `https://developer.android.com/reference/com/google/android/material/materialswitch/MaterialSwitch#setThumbIconSize(int)(int size)` Sets the size of the thumb icon. |
| `void` | `https://developer.android.com/reference/com/google/android/material/materialswitch/MaterialSwitch#setThumbIconTintList(ColorStateList)(ColorStateList tintList)` Applies a tint to the thumb icon drawable. |
| `void` | `https://developer.android.com/reference/com/google/android/material/materialswitch/MaterialSwitch#setThumbIconTintMode(PorterDuff.Mode)(Mode tintMode)` Specifies the blending mode used to apply the tint specified by `https://developer.android.com/reference/com/google/android/material/materialswitch/MaterialSwitch#setThumbIconTintList(ColorStateList)`} to the thumb icon drawable. |
| `void` | `https://developer.android.com/reference/com/google/android/material/materialswitch/MaterialSwitch#setThumbTintList(ColorStateList)(ColorStateList tintList)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/materialswitch/MaterialSwitch#setThumbTintMode(PorterDuff.Mode)(Mode tintMode)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/materialswitch/MaterialSwitch#setTrackDecorationDrawable(Drawable)(Drawable trackDecoration)` Set the drawable used for the track decoration that will be drawn upon the track. |
| `void` | `https://developer.android.com/reference/com/google/android/material/materialswitch/MaterialSwitch#setTrackDecorationResource(int)(int resId)` Set the drawable used for the track decoration that will be drawn upon the track. |
| `void` | `https://developer.android.com/reference/com/google/android/material/materialswitch/MaterialSwitch#setTrackDecorationTintList(ColorStateList)(ColorStateList tintList)` Applies a tint to the track decoration drawable. |
| `void` | `https://developer.android.com/reference/com/google/android/material/materialswitch/MaterialSwitch#setTrackDecorationTintMode(PorterDuff.Mode)(Mode tintMode)` Specifies the blending mode used to apply the tint specified by `https://developer.android.com/reference/com/google/android/material/materialswitch/MaterialSwitch#setTrackDecorationTintList(ColorStateList)`} to the track decoration drawable. |
| `void` | `https://developer.android.com/reference/com/google/android/material/materialswitch/MaterialSwitch#setTrackDrawable(Drawable)(Drawable track)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/materialswitch/MaterialSwitch#setTrackTintList(ColorStateList)(ColorStateList tintList)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/materialswitch/MaterialSwitch#setTrackTintMode(PorterDuff.Mode)(Mode tintMode)` |

| ### Protected methods |
|---|---|
| `int[]` | `https://developer.android.com/reference/com/google/android/material/materialswitch/MaterialSwitch#onCreateDrawableState(int)(int extraSpace)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/materialswitch/MaterialSwitch#onLayout(boolean,int,int,int,int)(boolean changed, int left, int top, int right, int bottom)` |

## Public fields

### thumbDrawable

```
public Drawable thumbDrawable
```

### thumbIconDrawable

```
public Drawable thumbIconDrawable
```

### thumbIconSize

```
public int thumbIconSize
```

### thumbIconTintList

```
public ColorStateList thumbIconTintList
```

### thumbIconTintMode

```
public Mode thumbIconTintMode
```

### thumbTintList

```
public ColorStateList thumbTintList
```

### trackDecorationDrawable

```
public Drawable trackDecorationDrawable
```

### trackDecorationTintList

```
public ColorStateList trackDecorationTintList
```

### trackDecorationTintMode

```
public Mode trackDecorationTintMode
```

### trackDrawable

```
public Drawable trackDrawable
```

### trackTintList

```
public ColorStateList trackTintList
```

## Public constructors

### MaterialSwitch

```
public MaterialSwitch(Context context)
```

### MaterialSwitch

```
public MaterialSwitch(Context context, AttributeSet attrs)
```

### MaterialSwitch

```
public MaterialSwitch(Context context, AttributeSet attrs, int defStyleAttr)
```

## Public methods

### getThumbDrawable

```
public Drawable getThumbDrawable()
```

### getThumbIconDrawable

```
public Drawable getThumbIconDrawable()
```

Gets the drawable used for the thumb icon that will be drawn upon the thumb.

ref com.google.android.material.R.styleable#MaterialSwitch_thumbIcon

### getThumbIconSize

```
public int getThumbIconSize()
```

Returns the size of the thumb icon.

ref com.google.android.material.R.styleable#MaterialSwitch_thumbIconSize

### getThumbIconTintList

```
public ColorStateList getThumbIconTintList()
```

Returns the tint applied to the thumb icon drawable

ref com.google.android.material.R.styleable#MaterialSwitch_thumbIconTint

### getThumbIconTintMode

```
public Mode getThumbIconTintMode()
```

Returns the blending mode used to apply the tint to the thumb icon drawable

ref com.google.android.material.R.styleable#MaterialSwitch_thumbIconTintMode

### getThumbTintList

```
public ColorStateList getThumbTintList()
```

### getTrackDecorationDrawable

```
public Drawable getTrackDecorationDrawable()
```

Get the drawable used for the track decoration that will be drawn upon the track.

ref com.google.android.material.R.styleable#MaterialSwitch_trackDecoration

### getTrackDecorationTintList

```
public ColorStateList getTrackDecorationTintList()
```

Returns the tint applied to the track decoration drawable

ref com.google.android.material.R.styleable#MaterialSwitch_trackDecorationTint

### getTrackDecorationTintMode

```
public Mode getTrackDecorationTintMode()
```

Returns the blending mode used to apply the tint to the track decoration drawable

ref com.google.android.material.R.styleable#MaterialSwitch_trackDecorationTintMode

### getTrackDrawable

```
public Drawable getTrackDrawable()
```

### getTrackTintList

```
public ColorStateList getTrackTintList()
```

### invalidate

```
public void invalidate()
```

### setThumbDrawable

```
public void setThumbDrawable(Drawable drawable)
```

### setThumbIconDrawable

```
public void setThumbIconDrawable(Drawable icon)
```

Sets the drawable used for the thumb icon that will be drawn upon the thumb.

ref com.google.android.material.R.styleable#MaterialSwitch_thumbIcon

| Parameters |
|---|---|
| `Drawable icon` | Thumb icon drawable |

### setThumbIconResource

```
public void setThumbIconResource(int resId)
```

Sets the drawable used for the thumb icon that will be drawn upon the thumb.

ref com.google.android.material.R.styleable#MaterialSwitch_thumbIcon

| Parameters |
|---|---|
| `int resId` | Resource ID of a thumb icon drawable |

### setThumbIconSize

```
public void setThumbIconSize(int size)
```

Sets the size of the thumb icon.

ref com.google.android.material.R.styleable#MaterialSwitch_thumbIconSize

### setThumbIconTintList

```
public void setThumbIconTintList(ColorStateList tintList)
```

Applies a tint to the thumb icon drawable. Does not modify the current tint mode, which is SRC_IN by default.

Subsequent calls to `https://developer.android.com/reference/com/google/android/material/materialswitch/MaterialSwitch#setThumbIconDrawable(Drawable)` will automatically mutate the drawable and apply the specified tint and tint mode using setTintList.

ref com.google.android.material.R.styleable#MaterialSwitch_thumbIconTint

| Parameters |
|---|---|
| `ColorStateList tintList` | the tint to apply, may be `null` to clear tint |

### setThumbIconTintMode

```
public void setThumbIconTintMode(Mode tintMode)
```

Specifies the blending mode used to apply the tint specified by `https://developer.android.com/reference/com/google/android/material/materialswitch/MaterialSwitch#setThumbIconTintList(ColorStateList)`} to the thumb icon drawable. The default mode is SRC_IN.

ref com.google.android.material.R.styleable#MaterialSwitch_thumbIconTintMode

| Parameters |
|---|---|
| `Mode tintMode` | the blending mode used to apply the tint |

### setThumbTintList

```
public void setThumbTintList(ColorStateList tintList)
```

### setThumbTintMode

```
public void setThumbTintMode(Mode tintMode)
```

### setTrackDecorationDrawable

```
public void setTrackDecorationDrawable(Drawable trackDecoration)
```

Set the drawable used for the track decoration that will be drawn upon the track.

ref com.google.android.material.R.styleable#MaterialSwitch_trackDecoration

| Parameters |
|---|---|
| `Drawable trackDecoration` | Track decoration drawable |

### setTrackDecorationResource

```
public void setTrackDecorationResource(int resId)
```

Set the drawable used for the track decoration that will be drawn upon the track.

ref com.google.android.material.R.styleable#MaterialSwitch_trackDecoration

| Parameters |
|---|---|
| `int resId` | Resource ID of a track decoration drawable |

### setTrackDecorationTintList

```
public void setTrackDecorationTintList(ColorStateList tintList)
```

Applies a tint to the track decoration drawable. Does not modify the current tint mode, which is SRC_IN by default.

Subsequent calls to `https://developer.android.com/reference/com/google/android/material/materialswitch/MaterialSwitch#setTrackDecorationDrawable(Drawable)` will automatically mutate the drawable and apply the specified tint and tint mode using setTintList.

ref com.google.android.material.R.styleable#MaterialSwitch_trackDecorationTint

| Parameters |
|---|---|
| `ColorStateList tintList` | the tint to apply, may be `null` to clear tint |

### setTrackDecorationTintMode

```
public void setTrackDecorationTintMode(Mode tintMode)
```

Specifies the blending mode used to apply the tint specified by `https://developer.android.com/reference/com/google/android/material/materialswitch/MaterialSwitch#setTrackDecorationTintList(ColorStateList)`} to the track decoration drawable. The default mode is SRC_IN.

ref com.google.android.material.R.styleable#MaterialSwitch_trackDecorationTintMode

| Parameters |
|---|---|
| `Mode tintMode` | the blending mode used to apply the tint |

### setTrackDrawable

```
public void setTrackDrawable(Drawable track)
```

### setTrackTintList

```
public void setTrackTintList(ColorStateList tintList)
```

### setTrackTintMode

```
public void setTrackTintMode(Mode tintMode)
```

## Protected methods

### onCreateDrawableState

```
protected int[] onCreateDrawableState(int extraSpace)
```

### onLayout

```
protected void onLayout(boolean changed, int left, int top, int right, int bottom)
```