MaterialSwitch

public class MaterialSwitch


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

For more information, see the component developer guidance and design guidelines.

Summary

Public fields

Drawable
Drawable
int
ColorStateList
Mode
ColorStateList
Drawable
ColorStateList
Mode
Drawable
ColorStateList

Public constructors

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

Public methods

Drawable
Drawable

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

int

Returns the size of the thumb icon.

ColorStateList

Returns the tint applied to the thumb icon drawable

Mode

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

ColorStateList
Drawable

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

ColorStateList

Returns the tint applied to the track decoration drawable

Mode

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

Drawable
ColorStateList
void
void
setThumbDrawable(Drawable drawable)
void
setThumbIconDrawable(Drawable icon)

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

void

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

void
setThumbIconSize(int size)

Sets the size of the thumb icon.

void
setThumbIconTintList(ColorStateList tintList)

Applies a tint to the thumb icon drawable.

void
setThumbIconTintMode(Mode tintMode)

Specifies the blending mode used to apply the tint specified by setThumbIconTintList} to the thumb icon drawable.

void
setThumbTintList(ColorStateList tintList)
void
setThumbTintMode(Mode tintMode)
void
setTrackDecorationDrawable(Drawable trackDecoration)

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

void

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

void
setTrackDecorationTintList(ColorStateList tintList)

Applies a tint to the track decoration drawable.

void

Specifies the blending mode used to apply the tint specified by setTrackDecorationTintList} to the track decoration drawable.

void
setTrackDrawable(Drawable track)
void
setTrackTintList(ColorStateList tintList)
void
setTrackTintMode(Mode tintMode)

Protected methods

int[]
onCreateDrawableState(int extraSpace)

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 setThumbIconDrawable 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 setThumbIconTintList} 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 setTrackDecorationDrawable 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 setTrackDecorationTintList} 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)