Android Dev Summit, October 23-24: two days of technical content, directly from the Android team. Sign-up for livestream updates.

SwitchMaterial

public class SwitchMaterial
extends SwitchCompat

java.lang.Object
   ↳ android.view.View
     ↳ android.widget.TextView
       ↳ android.widget.Button
         ↳ android.widget.CompoundButton
           ↳ androidx.appcompat.widget.SwitchCompat
             ↳ com.google.android.material.switchmaterial.SwitchMaterial


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 Switch, you must explicitly declare SwitchMaterial in your layout XML.

Summary

Inherited constants

From class android.widget.TextView
From class android.view.View

Inherited fields

From class android.view.View

Public constructors

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

Public methods

boolean isUseMaterialThemeColors()

Returns true if this SwitchMaterial defaults to colors from a Material Theme.

void setUseMaterialThemeColors(boolean useMaterialThemeColors)

Forces the SwitchMaterial to use colors from a Material Theme.

Protected methods

void onAttachedToWindow()

Inherited methods

From class androidx.appcompat.widget.SwitchCompat
From class android.widget.CompoundButton
From class android.widget.Button
From class android.widget.TextView
From class android.view.View
From class java.lang.Object
From interface android.widget.Checkable
From interface android.view.ViewTreeObserver.OnPreDrawListener
From interface android.graphics.drawable.Drawable.Callback
From interface android.view.KeyEvent.Callback
From interface android.view.accessibility.AccessibilityEventSource

Public constructors

SwitchMaterial

SwitchMaterial (Context context)

Parameters
context Context

SwitchMaterial

SwitchMaterial (Context context, 
                AttributeSet attrs)

Parameters
context Context

attrs AttributeSet

SwitchMaterial

SwitchMaterial (Context context, 
                AttributeSet attrs, 
                int defStyleAttr)

Parameters
context Context

attrs AttributeSet

defStyleAttr int

Public methods

isUseMaterialThemeColors

boolean isUseMaterialThemeColors ()

Returns true if this SwitchMaterial defaults to colors from a Material Theme.

Returns
boolean

setUseMaterialThemeColors

void setUseMaterialThemeColors (boolean useMaterialThemeColors)

Forces the 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(ColorStateList) and setThumbTintList(ColorStateList) to change tints.

Parameters
useMaterialThemeColors boolean

Protected methods

onAttachedToWindow

void onAttachedToWindow ()