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

Inherited fields

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

Public constructors

SwitchMaterial

public SwitchMaterial (Context context)

Parameters
context Context

SwitchMaterial

public SwitchMaterial (Context context, 
                AttributeSet attrs)

Parameters
context Context

attrs AttributeSet

SwitchMaterial

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

Parameters
context Context

attrs AttributeSet

defStyleAttr int

Public methods

isUseMaterialThemeColors

public boolean isUseMaterialThemeColors ()

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

Returns
boolean

setUseMaterialThemeColors

public 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 SwitchCompat.setTrackTintList(ColorStateList) and SwitchCompat.setThumbTintList(ColorStateList) to change tints.

Parameters
useMaterialThemeColors boolean

Protected methods

onAttachedToWindow

protected void onAttachedToWindow ()