# SwitchMaterial

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

*** ** * ** ***


```
public class SwitchMaterial
```

<br />

*** ** * ** ***

A class that creates a Material Themed Switch.

This class uses attributes from the Material Theme to style a Switch. Excepting color changes, it behaves identically to SwitchCompat. Your theme's `?attr/colorControlActivated`, `?attr/colorSurface`, and `?attr/colorOnSurface` must be set. Because SwitchCompat does not extend android.widget.Switch, you must explicitly declare `https://developer.android.com/reference/com/google/android/material/switchmaterial/SwitchMaterial` in your layout XML.

## Summary

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

| ### Public methods |
|---|---|
| `boolean` | `https://developer.android.com/reference/com/google/android/material/switchmaterial/SwitchMaterial#isUseMaterialThemeColors()()` Returns true if this `https://developer.android.com/reference/com/google/android/material/switchmaterial/SwitchMaterial` defaults to colors from a Material Theme. |
| `void` | `https://developer.android.com/reference/com/google/android/material/switchmaterial/SwitchMaterial#setUseMaterialThemeColors(boolean)(boolean useMaterialThemeColors)` Forces the `https://developer.android.com/reference/com/google/android/material/switchmaterial/SwitchMaterial` to use colors from a Material Theme. |

| ### Protected methods |
|---|---|
| `void` | `https://developer.android.com/reference/com/google/android/material/switchmaterial/SwitchMaterial#onAttachedToWindow()()` |

## Public constructors

### SwitchMaterial

```
public SwitchMaterial(Context context)
```

### SwitchMaterial

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

### SwitchMaterial

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

## Public methods

### isUseMaterialThemeColors

```
public boolean isUseMaterialThemeColors()
```

Returns true if this `https://developer.android.com/reference/com/google/android/material/switchmaterial/SwitchMaterial` defaults to colors from a Material Theme.

### setUseMaterialThemeColors

```
public void setUseMaterialThemeColors(boolean useMaterialThemeColors)
```

Forces the `https://developer.android.com/reference/com/google/android/material/switchmaterial/SwitchMaterial` to use colors from a Material Theme. Overrides any specified tint list for the track and thumb. If set to false, sets the tints to null. Use setTrackTintList and setThumbTintList to change tints.

## Protected methods

### onAttachedToWindow

```
protected void onAttachedToWindow()
```