Slider

public class Slider


A widget that allows picking a value within a given range by sliding a thumb along a horizontal line.

The slider can function either as a continuous slider, or as a discrete slider. The mode of operation is controlled by the value of the step size. If the step size is set to 0, the slider operates as a continuous slider where the slider's thumb can be moved to any position along the horizontal line. If the step size is set to a number greater than 0, the slider operates as a discrete slider where the slider's thumb will snap to the closest valid value. See * #setStepSize(float).

The interface defines a formatter to be used to render text within the value indicator label on interaction.

is a simple implementation of the that displays the selected value using letters to indicate magnitude (e.g.: 1.5K, 3M, 12B, etc..).

With the default style * com.google.android.material.R.style#Widget_MaterialComponents_Slider, colorPrimary and colorOnPrimary are used to customize the color of the slider when enabled, and colorOnSurface is used when disabled. The following attributes are used to customize the slider's appearance further:

  • haloColor}: the color of the halo around the thumb.
  • haloRadius}: The radius of the halo around the thumb.
  • labelBehavior}: The behavior of the label which can be LABEL_FLOATING}, LABEL_WITHIN_BOUNDS}, or LABEL_GONE}. See for more information.
  • labelStyle}: the style to apply to the value indicator .
  • thumbColor}: the color of the slider's thumb.
  • thumbStrokeColor}: the color of the thumb's stroke.
  • thumbStrokeWidth}: the width of the thumb's stroke.
  • thumbElevation}: the elevation of the slider's thumb.
  • thumbWidth}: The width of the slider's thumb.
  • thumbHeight}: The height of the slider's thumb.
  • thumbRadius}: The radius of the slider's thumb.
  • thumbTrackGapSize}: The size of the gap between the thumb and the track.
  • tickColorActive}: the color of the slider's tick marks for the active part of the track. Only used when the slider is in discrete mode.
  • tickColorInactive}: the color of the slider's tick marks for the inactive part of the track. Only used when the slider is in discrete mode.
  • tickColor}: the color of the slider's tick marks. Only used when the slider is in discrete mode. This is a short hand for setting both the tickColorActive} and *tickColorInactive to the same thing. This takes precedence over tickColorActive} and tickColorInactive}.
  • tickVisible} (deprecated, use tickVisibilityMode} instead): Whether to show the tick marks. Only used when the slider is in discrete mode.
  • tickVisibilityMode}: Mode to specify the visibility of tick marks. Only used when the slider is in discrete mode.
  • trackColorActive}: The color of the active part of the track.
  • trackColorInactive}: The color of the inactive part of the track.
  • trackColor}: The color of the whole track. This is a short hand for setting both the trackColorActive} and trackColorInactive} to the same thing. This takes precedence over trackColorActive} and trackColorInactive}.
  • trackHeight}: The height of the track.
  • trackCornerSize}: The corner size on the outside of the track.
  • trackInsideCornerSize}: The corner size on the inside of the track (visible with gap).
  • trackStopIndicatorSize}: The size of the stop indicator at the edges of the track.

The following XML attributes are used to set the slider's various parameters of operation:

  • android:valueFrom}: Required. The slider's minimum value. This attribute must be less than valueTo} or an will be thrown when the view is laid out.
  • android:valueTo}: Required. The slider's maximum value. This attribute must be greater than valueFrom} or an will be thrown when the view is laid out.
  • android:value}: Optional. The initial value of the slider. If not specified, the slider's minimum value android:valueFrom} is used.
  • android:stepSize}: Optional. This value dictates whether the slider operates in continuous mode, or in discrete mode. If missing or equal to 0, the slider operates in continuous mode. If greater than 0 and evenly divides the range described by *valueFrom and valueTo}, the slider operates in discrete mode. If negative an * is thrown, or if greater than 0 but not a factor of the range described by valueFrom} and valueTo}, an will be thrown when the view is laid out.

android:value: Optional. The initial value of the slider. If not specified, the slider's minimum value android:valueFrom is used.

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

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

Summary

Nested types

public interface Slider.OnChangeListener

Interface definition for a callback invoked when a slider's value is changed.

Interface definition for callbacks invoked when a slider's touch event is being started/stopped.

Public constructors

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

Public methods

void
addOnChangeListener(L listener)

Registers a callback to be invoked when the slider changes.

void

Registers a callback to be invoked when the slider touch event is being started or stopped

void

Removes all instances of attached to this slider

void

Removes all instances of touch listeners attached to this slider

boolean
dispatchHoverEvent(MotionEvent event)
boolean
dispatchKeyEvent(KeyEvent event)
CharSequence
int

Returns the index of the currently active thumb, or -1 if no thumb is active

int

Returns the index of the currently focused thumb

int

Returns the radius of the halo.

ColorStateList

Returns the color of the halo.

int

Returns the LabelBehavior used.

float

Returns the step size used to mark the ticks.

float

Returns the elevation of the thumb.

int

Returns the height of the thumb.

int

Returns the radius of the thumb.

ColorStateList

Gets the stroke color for the thumb.

float

Gets the stroke width for the thumb

ColorStateList

Returns the color of the thumb.

int

Returns the size of the gap between the thumb and the track.

int

Returns the width of the thumb.

int

Returns the radius of the active tick in pixels.

ColorStateList

Returns the color of the ticks on the active portion of the track.

int

Returns the radius of the inactive tick in pixels.

ColorStateList

Returns the color of the ticks on the inactive portion of the track.

ColorStateList

Returns the color of the tick if the active and inactive parts aren't different.

int

Returns the current tick visibility mode.

ColorStateList

Returns the color of the active portion of the track.

int

Returns the corner size on the outside of the track.

int

Returns the height of the track in pixels.

ColorStateList

Gets the active track icon color shown, if present.

Drawable

Gets the active track end icon shown, if present.

Drawable

Gets the active track start icon shown, if present.

ColorStateList

Gets the inactive track icon color shown, if present.

Drawable

Gets the inactive track end icon shown, if present.

Drawable

Gets the inactive track start icon shown, if present.

int

Gets the track icons size shown, if present.

ColorStateList

Returns the color of the inactive portion of the track.

int

Returns the corner size on the inside of the track (visible with gap).

int

Returns the side padding of the track.

int

Returns the size of the stop indicator at the edges of the track.

ColorStateList

Returns the color of the track if the active and inactive parts aren't different.

int

Returns the width of the track in pixels.

float

Returns the value of the slider.

float

Returns the slider's valueFrom value.

float

Returns the slider's valueTo value.

boolean

Returns true if the slider has a LabelFormatter attached, false otherwise.

boolean
boolean

Returns whether the tick marks are visible.

boolean
void
onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info)
boolean
onKeyDown(int keyCode, KeyEvent event)
boolean
onKeyUp(int keyCode, KeyEvent event)
boolean
onTouchEvent(MotionEvent event)
void
onVisibilityAggregated(boolean isVisible)
void

Removes a callback for value changes from this slider.

void

Removes a callback to be invoked when the slider touch event is being started or stopped

void
void
setCentered(boolean isCentered)

Sets the slider to be in centered configuration, meaning the starting value is positioned in the middle of the slider.

void
setCustomThumbDrawable(Drawable drawable)

Sets the custom thumb drawable which will be used for all value positions.

void
setCustomThumbDrawable(int drawableResId)

Sets the custom thumb drawable which will be used for all value positions.

void
setEnabled(boolean enabled)
void

Sets the index of the currently focused thumb

void
setHaloRadius(int radius)

Sets the radius of the halo in pixels.

void

Sets the radius of the halo from a dimension resource.

void
setHaloTintList(ColorStateList haloColor)

Sets the color of the halo.

void

Determines the LabelBehavior used.

void

Registers a LabelFormatter to be used to format the value displayed in the bubble shown when the slider operates in discrete mode.

void
void
setStepSize(float stepSize)

Sets the step size to use to mark the ticks.

void
setThumbElevation(float elevation)

Sets the elevation of the thumb.

void

Sets the elevation of the thumb from a dimension resource.

void
setThumbHeight(int height)

Sets the height of the thumb in pixels.

void

Sets the height of the thumb from a dimension resource.

void
setThumbRadius(int radius)

Sets the radius of the thumb in pixels.

void

Sets the radius of the thumb from a dimension resource.

void
setThumbStrokeColor(ColorStateList thumbStrokeColor)

Sets the stroke color for the thumbs.

void
setThumbStrokeColorResource(int thumbStrokeColorResourceId)

Sets the stroke color resource for the thumbs.

void
setThumbStrokeWidth(float thumbStrokeWidth)

Sets the stroke width for the thumb.

void
setThumbStrokeWidthResource(int thumbStrokeWidthResourceId)

Sets the stroke width dimension resource for the thumb.Both thumbStroke color and thumbStroke width must be set for a stroke to be drawn.

void
setThumbTintList(ColorStateList thumbColor)

Sets the color of the thumb.

void
setThumbTrackGapSize(int thumbTrackGapSize)

Sets the size of the gap between the thumb and the track.

void
setThumbWidth(int width)

Sets the width of the thumb in pixels.

void

Sets the width of the thumb from a dimension resource.

void
setTickActiveRadius(int tickActiveRadius)

Set the radius of the active tick in pixels.

void
setTickActiveTintList(ColorStateList tickColor)

Sets the color of the ticks on the active portion of the track.

void
setTickInactiveRadius(int tickInactiveRadius)

Set the radius of the inactive tick in pixels.

void
setTickInactiveTintList(ColorStateList tickColor)

Sets the color of the ticks on the inactive portion of the track.

void
setTickTintList(ColorStateList tickColor)

Sets the color of the tick marks.

void
setTickVisibilityMode(@TickVisibilityMode int tickVisibilityMode)

Sets the tick visibility mode.

void
setTickVisible(boolean tickVisible)

This method is deprecated.

Use setTickVisibilityMode instead.

void
setTrackActiveTintList(ColorStateList trackColor)

Sets the color of the active portion of the track.

void
setTrackCornerSize(int cornerSize)

Sets the corner size on the outside of the track.

void
setTrackHeight(int trackHeight)

Set the height of the track in pixels.

void
setTrackIconActiveColor(ColorStateList color)

Sets the active track icon color.

void
setTrackIconActiveEnd(Drawable icon)

Sets the active track end icon.

void
setTrackIconActiveEnd(int iconResourceId)

Sets the active track end icon.

void
setTrackIconActiveStart(Drawable icon)

Sets the active track start icon.

void
setTrackIconActiveStart(int iconResourceId)

Sets the active track start icon.

void
setTrackIconInactiveColor(ColorStateList color)

Sets the inactive track icon color.

void
setTrackIconInactiveEnd(Drawable icon)

Sets the inactive track end icon.

void
setTrackIconInactiveEnd(int iconResourceId)

Sets the inactive track end icon.

void

Sets the inactive track start icon.

void
setTrackIconInactiveStart(int iconResourceId)

Sets the inactive track start icon.

void
setTrackIconSize(int size)

Sets the track icons size.

void
setTrackInactiveTintList(ColorStateList trackColor)

Sets the color of the inactive portion of the track.

void
setTrackInsideCornerSize(int cornerSize)

Sets the corner size on the inside of the track (visible with gap).

void
setTrackStopIndicatorSize(int trackStopIndicatorSize)

Sets the size of the stop indicator at the edges of the track.

void
setTrackTintList(ColorStateList trackColor)

Sets the color of the track.

void
setValue(float value)

Sets the value of the slider.

void
setValueFrom(float valueFrom)

Sets the slider's valueFrom value.

void
setValueTo(float valueTo)

Sets the slider's valueTo value.

Protected methods

void
float
void
void
void
onDraw(Canvas canvas)
void
onFocusChanged(
    boolean gainFocus,
    int direction,
    Rect previouslyFocusedRect
)
void
onMeasure(int widthMeasureSpec, int heightMeasureSpec)
void
onRestoreInstanceState(Parcelable state)
Parcelable
void
onSizeChanged(int w, int h, int oldw, int oldh)
void
onVisibilityChanged(View changedView, int visibility)
boolean

Tries to pick the active thumb if one hasn't already been set.

void
void
setSeparationUnit(int separationUnit)

Public fields

haloRadius

public int haloRadius

labelBehavior

public int labelBehavior

stepSize

public float stepSize

thumbHeight

public int thumbHeight

thumbTrackGapSize

public int thumbTrackGapSize

thumbWidth

public int thumbWidth

tickActiveRadius

public int tickActiveRadius

tickInactiveRadius

public int tickInactiveRadius

tickVisibilityMode

public int tickVisibilityMode

trackCornerSize

public int trackCornerSize

trackIconActiveColor

public ColorStateList trackIconActiveColor

trackIconActiveEnd

public Drawable trackIconActiveEnd

trackIconActiveStart

public Drawable trackIconActiveStart

trackIconInactiveColor

public ColorStateList trackIconInactiveColor

trackIconInactiveEnd

public Drawable trackIconInactiveEnd

trackIconInactiveStart

public Drawable trackIconInactiveStart

trackIconSize

public int trackIconSize

trackInsideCornerSize

public int trackInsideCornerSize

trackSidePadding

public int trackSidePadding

trackStopIndicatorSize

public int trackStopIndicatorSize

trackWidth

public int trackWidth

valueFrom

public float valueFrom

valueTo

public float valueTo

Public constructors

Slider

public Slider(Context context)

Slider

public Slider(Context context, AttributeSet attrs)

Slider

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

Public methods

addOnChangeListener

public void addOnChangeListener(L listener)

Registers a callback to be invoked when the slider changes. On the RangeSlider implementation, the listener is invoked once for each value.

Parameters
L listener

The callback to run when the slider changes

addOnSliderTouchListener

public void addOnSliderTouchListener(T listener)

Registers a callback to be invoked when the slider touch event is being started or stopped

Parameters
T listener

The callback to run when the slider starts or stops being touched

clearOnChangeListeners

public void clearOnChangeListeners()

Removes all instances of attached to this slider

clearOnSliderTouchListeners

public void clearOnSliderTouchListeners()

Removes all instances of touch listeners attached to this slider

dispatchHoverEvent

public boolean dispatchHoverEvent(MotionEvent event)

dispatchKeyEvent

public boolean dispatchKeyEvent(KeyEvent event)

getAccessibilityClassName

public CharSequence getAccessibilityClassName()

getActiveThumbIndex

public int getActiveThumbIndex()

Returns the index of the currently active thumb, or -1 if no thumb is active

getFocusedThumbIndex

public int getFocusedThumbIndex()

Returns the index of the currently focused thumb

getHaloRadius

public int getHaloRadius()

Returns the radius of the halo.

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

getHaloTintList

public ColorStateList getHaloTintList()

Returns the color of the halo.

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

See also
setHaloTintList

getLabelBehavior

@BaseSlider.LabelBehavior
public int getLabelBehavior()

Returns the LabelBehavior used.

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

See also
setLabelBehavior

getStepSize

public float getStepSize()

Returns the step size used to mark the ticks.

A step size of 0 means that the slider is operating in continuous mode. A step size greater than 0 means that the slider is operating in discrete mode.

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

See also
setStepSize

getThumbElevation

public float getThumbElevation()

Returns the elevation of the thumb.

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

getThumbHeight

public int getThumbHeight()

Returns the height of the thumb. Note that setting this will also affect custom drawables set through setCustomThumbDrawable, setCustomThumbDrawable, setCustomThumbDrawablesForValues, and setCustomThumbDrawablesForValues.

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

getThumbRadius

public int getThumbRadius()

Returns the radius of the thumb. Note that setting this will also affect custom drawables set through setCustomThumbDrawable, setCustomThumbDrawable, setCustomThumbDrawablesForValues, and setCustomThumbDrawablesForValues.

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

getThumbStrokeColor

public ColorStateList getThumbStrokeColor()

Gets the stroke color for the thumb.

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

Returns
ColorStateList

The color used for the stroke in the thumb.

getThumbStrokeWidth

public float getThumbStrokeWidth()

Gets the stroke width for the thumb

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

Returns
float

Stroke width for the thumb.

getThumbTintList

public ColorStateList getThumbTintList()

Returns the color of the thumb.

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

See also
setThumbTintList

getThumbTrackGapSize

public int getThumbTrackGapSize()

Returns the size of the gap between the thumb and the track.

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

getThumbWidth

public int getThumbWidth()

Returns the width of the thumb. Note that setting this will also affect custom drawables set through setCustomThumbDrawable, setCustomThumbDrawable, setCustomThumbDrawablesForValues, and setCustomThumbDrawablesForValues.

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

getTickActiveRadius

public int getTickActiveRadius()

Returns the radius of the active tick in pixels.

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

getTickActiveTintList

public ColorStateList getTickActiveTintList()

Returns the color of the ticks on the active portion of the track.

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

getTickInactiveRadius

public int getTickInactiveRadius()

Returns the radius of the inactive tick in pixels.

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

getTickInactiveTintList

public ColorStateList getTickInactiveTintList()

Returns the color of the ticks on the inactive portion of the track.

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

getTickTintList

public ColorStateList getTickTintList()

Returns the color of the tick if the active and inactive parts aren't different.

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

Throws
java.lang.IllegalStateException

If tickColorActive and tickColorInactive have been set to different values.

getTickVisibilityMode

@TickVisibilityMode
public int getTickVisibilityMode()

Returns the current tick visibility mode.

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

getTrackActiveTintList

public ColorStateList getTrackActiveTintList()

Returns the color of the active portion of the track.

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

getTrackCornerSize

public int getTrackCornerSize()

Returns the corner size on the outside of the track.

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

getTrackHeight

public int getTrackHeight()

Returns the height of the track in pixels.

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

See also
setTrackHeight

getTrackIconActiveColor

public ColorStateList getTrackIconActiveColor()

Gets the active track icon color shown, if present.

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

Returns
ColorStateList

Color of the icon shown for this active track, if present.

getTrackIconActiveEnd

public Drawable getTrackIconActiveEnd()

Gets the active track end icon shown, if present.

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

Returns
Drawable

End icon shown for this active track, if present.

getTrackIconActiveStart

public Drawable getTrackIconActiveStart()

Gets the active track start icon shown, if present.

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

Returns
Drawable

Start icon shown for this active track, if present.

getTrackIconInactiveColor

public ColorStateList getTrackIconInactiveColor()

Gets the inactive track icon color shown, if present.

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

Returns
ColorStateList

Color of the icon shown for this inactive track, if present.

getTrackIconInactiveEnd

public Drawable getTrackIconInactiveEnd()

Gets the inactive track end icon shown, if present.

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

Returns
Drawable

End icon shown for this inactive track, if present.

getTrackIconInactiveStart

public Drawable getTrackIconInactiveStart()

Gets the inactive track start icon shown, if present.

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

Returns
Drawable

Start icon shown for this inactive track, if present.

getTrackIconSize

public int getTrackIconSize()

Gets the track icons size shown, if present.

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

Returns
int

Size of the icons shown for this track, if present.

See also
setTrackIconSize

getTrackInactiveTintList

public ColorStateList getTrackInactiveTintList()

Returns the color of the inactive portion of the track.

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

getTrackInsideCornerSize

public int getTrackInsideCornerSize()

Returns the corner size on the inside of the track (visible with gap).

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

getTrackSidePadding

public int getTrackSidePadding()

Returns the side padding of the track.

getTrackStopIndicatorSize

public int getTrackStopIndicatorSize()

Returns the size of the stop indicator at the edges of the track.

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

getTrackTintList

public ColorStateList getTrackTintList()

Returns the color of the track if the active and inactive parts aren't different.

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

Throws
java.lang.IllegalStateException

If trackColorActive and trackColorInactive have been set to different values.

getTrackWidth

public int getTrackWidth()

Returns the width of the track in pixels.

getValue

public float getValue()

Returns the value of the slider.

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

See also
setValue

getValueFrom

public float getValueFrom()

Returns the slider's valueFrom value.

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

See also
setValueFrom

getValueTo

public float getValueTo()

Returns the slider's valueTo value.

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

See also
setValueTo

hasLabelFormatter

public boolean hasLabelFormatter()

Returns true if the slider has a LabelFormatter attached, false otherwise.

isCentered

public boolean isCentered()

isTickVisible

public boolean isTickVisible()

Returns whether the tick marks are visible. Only used when the slider is in discrete mode.

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

isVertical

public boolean isVertical()

onInitializeAccessibilityNodeInfo

public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info)

onKeyDown

public boolean onKeyDown(int keyCode, KeyEvent event)

onKeyUp

public boolean onKeyUp(int keyCode, KeyEvent event)

onTouchEvent

public boolean onTouchEvent(MotionEvent event)

onVisibilityAggregated

public void onVisibilityAggregated(boolean isVisible)

removeOnChangeListener

public void removeOnChangeListener(L listener)

Removes a callback for value changes from this slider.

Parameters
L listener

The callback that'll stop receive slider changes

removeOnSliderTouchListener

public void removeOnSliderTouchListener(T listener)

Removes a callback to be invoked when the slider touch event is being started or stopped

Parameters
T listener

The callback that'll stop be notified when the slider is being touched

scheduleTooltipTimeout

public void scheduleTooltipTimeout()

setCentered

public void setCentered(boolean isCentered)

Sets the slider to be in centered configuration, meaning the starting value is positioned in the middle of the slider.

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

Parameters
boolean isCentered

boolean to use for the slider's centered configuration.

See also
isCentered

setCustomThumbDrawable

public void setCustomThumbDrawable(Drawable drawable)

Sets the custom thumb drawable which will be used for all value positions. Note that the custom drawable provided will be resized to match the thumb radius set by #setThumbRadius(int) or #setThumbRadiusResource(int). Be aware that the image quality may be compromised during resizing.

setCustomThumbDrawable

public void setCustomThumbDrawable(int drawableResId)

Sets the custom thumb drawable which will be used for all value positions. Note that the custom drawable provided will be resized to match the thumb radius set by #setThumbRadius(int) or #setThumbRadiusResource(int). Be aware that the image quality may be compromised during resizing.

setEnabled

public void setEnabled(boolean enabled)

setFocusedThumbIndex

public void setFocusedThumbIndex(int index)

Sets the index of the currently focused thumb

setHaloRadius

public void setHaloRadius(int radius)

Sets the radius of the halo in pixels.

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

See also
getHaloRadius

setHaloRadiusResource

public void setHaloRadiusResource(int radius)

Sets the radius of the halo from a dimension resource.

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

See also
getHaloRadius

setHaloTintList

public void setHaloTintList(ColorStateList haloColor)

Sets the color of the halo.

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

See also
getHaloTintList

setLabelBehavior

public void setLabelBehavior(@BaseSlider.LabelBehavior int labelBehavior)

Determines the LabelBehavior used.

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

setLabelFormatter

public void setLabelFormatter(LabelFormatter formatter)

Registers a LabelFormatter to be used to format the value displayed in the bubble shown when the slider operates in discrete mode.

Parameters
LabelFormatter formatter

The LabelFormatter to use to format the bubble's text

setOrientation

public void setOrientation(@BaseSlider.Orientation int orientation)

setStepSize

public void setStepSize(float stepSize)

Sets the step size to use to mark the ticks.

Setting this value to 0 will make the slider operate in continuous mode. Setting this value to a number greater than 0 will make the slider operate in discrete mode.

The step size must evenly divide the range described by the valueFrom and valueTo, it must be a factor of the range. If the step size is not a factor of the range, an IllegalStateException will be thrown when this view is laid out.

Setting this value to a negative value will result in an IllegalArgumentException.

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

Parameters
float stepSize

The interval value at which ticks must be drawn. Set to 0 to operate the slider in continuous mode and not have any ticks.

Throws
java.lang.IllegalArgumentException

If the step size is less than 0

See also
getStepSize

setThumbElevation

public void setThumbElevation(float elevation)

Sets the elevation of the thumb.

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

setThumbElevationResource

public void setThumbElevationResource(int elevation)

Sets the elevation of the thumb from a dimension resource.

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

setThumbHeight

public void setThumbHeight(int height)

Sets the height of the thumb in pixels. Note that setting this will also affect custom drawables set through setCustomThumbDrawable, setCustomThumbDrawable, setCustomThumbDrawablesForValues, and setCustomThumbDrawablesForValues.

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

See also
getThumbHeight

setThumbHeightResource

public void setThumbHeightResource(int height)

Sets the height of the thumb from a dimension resource. Note that setting this will also affect custom drawables set through setCustomThumbDrawable, setCustomThumbDrawable, setCustomThumbDrawablesForValues, and setCustomThumbDrawablesForValues.

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

See also
getThumbHeight

setThumbRadius

public void setThumbRadius(int radius)

Sets the radius of the thumb in pixels. Note that setting this will also affect custom drawables set through setCustomThumbDrawable, setCustomThumbDrawable, setCustomThumbDrawablesForValues, and setCustomThumbDrawablesForValues.

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

See also
getThumbRadius

setThumbRadiusResource

public void setThumbRadiusResource(int radius)

Sets the radius of the thumb from a dimension resource. Note that setting this will also affect custom drawables set through setCustomThumbDrawable, setCustomThumbDrawable, setCustomThumbDrawablesForValues, and setCustomThumbDrawablesForValues.

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

See also
getThumbRadius

setThumbStrokeColor

public void setThumbStrokeColor(ColorStateList thumbStrokeColor)

Sets the stroke color for the thumbs. Both thumbStroke color and thumbStroke width must be set for a stroke to be drawn.

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

Parameters
ColorStateList thumbStrokeColor

Color to use for the stroke in the thumbs.

setThumbStrokeColorResource

public void setThumbStrokeColorResource(int thumbStrokeColorResourceId)

Sets the stroke color resource for the thumbs. Both thumbStroke color and thumbStroke width must be set for a stroke to be drawn.

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

Parameters
int thumbStrokeColorResourceId

Color resource to use for the stroke.

setThumbStrokeWidth

public void setThumbStrokeWidth(float thumbStrokeWidth)

Sets the stroke width for the thumb. Both thumbStroke color and thumbStroke width must be set for a stroke to be drawn.

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

Parameters
float thumbStrokeWidth

Stroke width for the thumb

setThumbStrokeWidthResource

public void setThumbStrokeWidthResource(int thumbStrokeWidthResourceId)

Sets the stroke width dimension resource for the thumb.Both thumbStroke color and thumbStroke width must be set for a stroke to be drawn.

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

Parameters
int thumbStrokeWidthResourceId

Stroke width dimension resource for the thumb

setThumbTintList

public void setThumbTintList(ColorStateList thumbColor)

Sets the color of the thumb.

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

See also
getThumbTintList

setThumbTrackGapSize

public void setThumbTrackGapSize(int thumbTrackGapSize)

Sets the size of the gap between the thumb and the track.

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

setThumbWidth

public void setThumbWidth(int width)

Sets the width of the thumb in pixels. Note that setting this will also affect custom drawables set through setCustomThumbDrawable, setCustomThumbDrawable, setCustomThumbDrawablesForValues, and setCustomThumbDrawablesForValues.

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

See also
getThumbWidth

setThumbWidthResource

public void setThumbWidthResource(int width)

Sets the width of the thumb from a dimension resource. Note that setting this will also affect custom drawables set through setCustomThumbDrawable, setCustomThumbDrawable, setCustomThumbDrawablesForValues, and setCustomThumbDrawablesForValues.

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

See also
getThumbWidth

setTickActiveRadius

public void setTickActiveRadius(int tickActiveRadius)

Set the radius of the active tick in pixels.

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

setTickActiveTintList

public void setTickActiveTintList(ColorStateList tickColor)

Sets the color of the ticks on the active portion of the track.

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

setTickInactiveRadius

public void setTickInactiveRadius(int tickInactiveRadius)

Set the radius of the inactive tick in pixels.

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

setTickInactiveTintList

public void setTickInactiveTintList(ColorStateList tickColor)

Sets the color of the ticks on the inactive portion of the track.

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

setTickTintList

public void setTickTintList(ColorStateList tickColor)

Sets the color of the tick marks.

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

setTickVisibilityMode

public void setTickVisibilityMode(@TickVisibilityMode int tickVisibilityMode)

Sets the tick visibility mode. Only used when the slider is in discrete mode.

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

setTickVisible

public void setTickVisible(boolean tickVisible)

Sets whether the tick marks are visible. Only used when the slider is in discrete mode.

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

Parameters
boolean tickVisible

The visibility of tick marks.

setTrackActiveTintList

public void setTrackActiveTintList(ColorStateList trackColor)

Sets the color of the active portion of the track.

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

setTrackCornerSize

public void setTrackCornerSize(int cornerSize)

Sets the corner size on the outside of the track.

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

setTrackHeight

public void setTrackHeight(int trackHeight)

Set the height of the track in pixels.

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

See also
getTrackHeight

setTrackIconActiveColor

public void setTrackIconActiveColor(ColorStateList color)

Sets the active track icon color.

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

Parameters
ColorStateList color

color to use for the active track's icon.

setTrackIconActiveEnd

public void setTrackIconActiveEnd(Drawable icon)

Sets the active track end icon.

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

Parameters
Drawable icon

Drawable to use for the active track's end icon.

setTrackIconActiveEnd

public void setTrackIconActiveEnd(int iconResourceId)

Sets the active track end icon.

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

Parameters
int iconResourceId

Drawable resource ID to use for the active track's end icon.

setTrackIconActiveStart

public void setTrackIconActiveStart(Drawable icon)

Sets the active track start icon.

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

Parameters
Drawable icon

Drawable to use for the active track's start icon.

setTrackIconActiveStart

public void setTrackIconActiveStart(int iconResourceId)

Sets the active track start icon.

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

Parameters
int iconResourceId

Drawable resource ID to use for the active track's start icon.

setTrackIconInactiveColor

public void setTrackIconInactiveColor(ColorStateList color)

Sets the inactive track icon color.

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

Parameters
ColorStateList color

color to use for the inactive track's icon.

setTrackIconInactiveEnd

public void setTrackIconInactiveEnd(Drawable icon)

Sets the inactive track end icon.

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

Parameters
Drawable icon

Drawable to use for the inactive track's end icon.

setTrackIconInactiveEnd

public void setTrackIconInactiveEnd(int iconResourceId)

Sets the inactive track end icon.

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

Parameters
int iconResourceId

Drawable resource ID to use for the inactive track's end icon.

setTrackIconInactiveStart

public void setTrackIconInactiveStart(Drawable icon)

Sets the inactive track start icon.

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

Parameters
Drawable icon

Drawable to use for the inactive track's start icon.

setTrackIconInactiveStart

public void setTrackIconInactiveStart(int iconResourceId)

Sets the inactive track start icon.

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

Parameters
int iconResourceId

Drawable resource ID to use for the inactive track's start icon.

setTrackIconSize

public void setTrackIconSize(int size)

Sets the track icons size.

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

Parameters
int size

size to use for the track icons.

See also
getTrackIconSize

setTrackInactiveTintList

public void setTrackInactiveTintList(ColorStateList trackColor)

Sets the color of the inactive portion of the track.

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

setTrackInsideCornerSize

public void setTrackInsideCornerSize(int cornerSize)

Sets the corner size on the inside of the track (visible with gap).

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

setTrackStopIndicatorSize

public void setTrackStopIndicatorSize(int trackStopIndicatorSize)

Sets the size of the stop indicator at the edges of the track.

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

setTrackTintList

public void setTrackTintList(ColorStateList trackColor)

Sets the color of the track.

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

setValue

public void setValue(float value)

Sets the value of the slider.

The thumb value must be greater or equal to valueFrom, and lesser or equal to valueTo. If that is not the case, an IllegalStateException will be thrown when the view is laid out.

If the slider is in discrete mode (i.e. the tick increment value is greater than 0), the thumb's value must be set to a value falls on a tick (i.e.: value == valueFrom + x * stepSize, where x is an integer equal to or greater than 0). If that is not the case, an IllegalStateException will be thrown when the view is laid out.

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

Parameters
float value

The value to which to set the slider

See also
getValue

setValueFrom

public void setValueFrom(float valueFrom)

Sets the slider's valueFrom value.

The valueFrom value must be strictly lower than the valueTo value. If that is not the case, an IllegalStateException will be thrown when the view is laid out.

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

Parameters
float valueFrom

The minimum value for the slider's range of values

See also
getValueFrom

setValueTo

public void setValueTo(float valueTo)

Sets the slider's valueTo value.

The valueTo value must be strictly greater than the valueFrom value. If that is not the case, an IllegalStateException will be thrown when the view is laid out.

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

Parameters
float valueTo

The maximum value for the slider's range of values

See also
getValueTo

Protected methods

drawableStateChanged

protected void drawableStateChanged()

getMinSeparation

protected float getMinSeparation()

onAttachedToWindow

protected void onAttachedToWindow()

onDetachedFromWindow

protected void onDetachedFromWindow()

onDraw

protected void onDraw(Canvas canvas)

onFocusChanged

protected void onFocusChanged(
    boolean gainFocus,
    int direction,
    Rect previouslyFocusedRect
)

onMeasure

protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)

onRestoreInstanceState

protected void onRestoreInstanceState(Parcelable state)

onSaveInstanceState

protected Parcelable onSaveInstanceState()

onSizeChanged

protected void onSizeChanged(int w, int h, int oldw, int oldh)

onVisibilityChanged

protected void onVisibilityChanged(View changedView, int visibility)

pickActiveThumb

protected boolean pickActiveThumb()

Tries to pick the active thumb if one hasn't already been set. This will pick the closest thumb if there is only one thumb under the touch position. If there is more than one thumb under the touch position, it will wait for enough drag left or right to determine which thumb to pick.

setActiveThumbIndex

protected void setActiveThumbIndex(int index)

setSeparationUnit

protected void setSeparationUnit(int separationUnit)