Google은 흑인 공동체를 위한 인종 간 평등을 진전시키기 위해 노력하고 있습니다. Google에서 어떤 노력을 하고 있는지 확인하세요.

RangeSlider

public class RangeSlider
extends View

java.lang.Object
   ↳ android.view.View
     ↳ com.google.android.material.slider.RangeSlider


A range slider can be used to select from either a continuous or a discrete set of values. The default is to use a continuous range of values from valueFrom to valueTo.

app:values: Optional. The initial values of the range slider. If not specified, the range slider will only have one value equal to android:valueFrom

app:minSeparation: Optional. The minimum distance between two thumbs that would otherwise overlap.

Summary

Nested classes

interface RangeSlider.OnChangeListener

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

interface RangeSlider.OnSliderTouchListener

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

XML attributes

RangeSlider_minSeparation  
RangeSlider_values  
Slider_android_stepSize  
Slider_android_valueFrom  
Slider_android_valueTo  
Slider_haloColor  
Slider_haloRadius  
Slider_labelBehavior  
Slider_thumbColor  
Slider_thumbElevation  
Slider_thumbRadius  
Slider_thumbStrokeColor  
Slider_thumbStrokeWidth  
Slider_tickColor  
Slider_tickColorActive  
Slider_tickColorInactive  
Slider_tickVisible  
Slider_trackColor  
Slider_trackColorActive  
Slider_trackColorInactive  
Slider_trackHeight  

Inherited constants

Inherited fields

Public constructors

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

Public methods

void addOnChangeListener(L listener)

Registers a callback to be invoked when the slider changes.

void addOnSliderTouchListener(T listener)

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

void clearOnChangeListeners()

Removes all instances of attached to this slider

void clearOnSliderTouchListeners()

Removes all instances of touch listeners attached to this slider

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

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

int getFocusedThumbIndex()

Returns the index of the currently focused thumb

int getHaloRadius()

Returns the radius of the halo.

ColorStateList getHaloTintList()

Returns the color of the halo.

int getLabelBehavior()

Returns the ERROR(/LabelBehavior) used.

float getMinSeparation()

Returns the minimum separation between two thumbs

float getStepSize()

Returns the step size used to mark the ticks.

float getThumbElevation()

Returns the elevation of the thumb.

int getThumbRadius()

Returns the radius of the thumb.

ColorStateList getThumbStrokeColor()

Gets the stroke color for the thumb.

float getThumbStrokeWidth()

Gets the stroke width for the thumb

ColorStateList getThumbTintList()

Returns the color of the thumb.

ColorStateList getTickActiveTintList()

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

ColorStateList getTickInactiveTintList()

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

ColorStateList getTickTintList()

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

ColorStateList getTrackActiveTintList()

Returns the color of the active portion of the track.

int getTrackHeight()

Returns the height of the track in pixels.

ColorStateList getTrackInactiveTintList()

Returns the color of the inactive portion of the track.

int getTrackSidePadding()

Returns the side padding of the track.

ColorStateList getTrackTintList()

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

int getTrackWidth()

Returns the width of the track in pixels.

float getValueFrom()

Returns the slider's valueFrom value.

float getValueTo()

Returns the slider's valueTo value.

List<Float> getValues()

Returns current values of the slider thumbs.

boolean hasLabelFormatter()

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

boolean isTickVisible()

Returns whether the tick marks are visible.

boolean onKeyDown(int keyCode, KeyEvent event)
boolean onKeyUp(int keyCode, KeyEvent event)
Parcelable onSaveInstanceState()
boolean onTouchEvent(MotionEvent event)
void removeOnChangeListener(L listener)

Removes a callback for value changes from this slider.

void removeOnSliderTouchListener(T listener)

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

void setEnabled(boolean enabled)
void setFocusedThumbIndex(int index)

Sets the index of the currently focused thumb

void setHaloRadius(int radius)

Sets the radius of the halo in pixels.

void setHaloRadiusResource(int radius)

Sets the radius of the halo from a dimension resource.

void setHaloTintList(ColorStateList haloColor)

Sets the color of the halo.

void setLabelBehavior(int labelBehavior)

Determines the ERROR(/LabelBehavior) used.

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.

void setMinSeparation(float minSeparation)

Sets the minimum separation between two thumbs

void setMinSeparationValue(float minSeparation)

Sets the minimum separation in the value scale.

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 setThumbElevationResource(int elevation)

Sets the elevation of the thumb from a dimension resource.

void setThumbRadius(int radius)

Sets the radius of the thumb in pixels.

void setThumbRadiusResource(int radius)

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 setTickActiveTintList(ColorStateList tickColor)

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

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 setTickVisible(boolean tickVisible)

Sets whether the tick marks are visible.

void setTrackActiveTintList(ColorStateList trackColor)

Sets the color of the active portion of the track.

void setTrackHeight(int trackHeight)

Set the height of the track in pixels.

void setTrackInactiveTintList(ColorStateList trackColor)

Sets the color of the inactive portion of the track.

void setTrackTintList(ColorStateList trackColor)

Sets the color of the track.

void setValueFrom(float valueFrom)

Sets the slider's valueFrom value.

void setValueTo(float valueTo)

Sets the slider's valueTo value.

void setValues(List<Float> values)

Sets multiple values for the slider.

void setValues(Float... values)

Sets multiple values for the slider.

Protected methods

void drawableStateChanged()
void onAttachedToWindow()
void onDetachedFromWindow()
void onDraw(Canvas canvas)
void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect)
void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
void onRestoreInstanceState(Parcelable state)
void onSizeChanged(int w, int h, int oldw, int oldh)
boolean pickActiveThumb()

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

void setActiveThumbIndex(int index)
void setSeparationUnit(int separationUnit)

Inherited methods

XML attributes

RangeSlider_minSeparation

Related methods:

RangeSlider_values

Slider_android_stepSize

Related methods:

Slider_android_valueFrom

Related methods:

Slider_android_valueTo

Related methods:

Slider_haloColor

Related methods:

Slider_haloRadius

Related methods:

Slider_labelBehavior

Related methods:

Slider_thumbColor

Related methods:

Slider_thumbElevation

Related methods:

Slider_thumbRadius

Related methods:

Slider_thumbStrokeColor

Related methods:

Slider_thumbStrokeWidth

Related methods:

Slider_tickColor

Related methods:

Slider_tickColorActive

Related methods:

Slider_tickColorInactive

Related methods:

Slider_tickVisible

Related methods:

Slider_trackColor

Related methods:

Slider_trackColorActive

Related methods:

Slider_trackColorInactive

Related methods:

Slider_trackHeight

Related methods:

Public constructors

RangeSlider

public RangeSlider (Context context)

Parameters
context Context

RangeSlider

public RangeSlider (Context context, 
                AttributeSet attrs)

Parameters
context Context

attrs AttributeSet

RangeSlider

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

Parameters
context Context

attrs AttributeSet

defStyleAttr int

Public methods

addOnChangeListener

public void addOnChangeListener (L listener)

Registers a callback to be invoked when the slider changes.

Parameters
listener L: 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
listener T: 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)

Parameters
event MotionEvent

Returns
boolean

dispatchKeyEvent

public boolean dispatchKeyEvent (KeyEvent event)

Parameters
event KeyEvent

Returns
boolean

getAccessibilityClassName

public CharSequence getAccessibilityClassName ()

Returns
CharSequence

getActiveThumbIndex

public int getActiveThumbIndex ()

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

Returns
int

getFocusedThumbIndex

public int getFocusedThumbIndex ()

Returns the index of the currently focused thumb

Returns
int

getHaloRadius

public int getHaloRadius ()

Returns the radius of the halo.

Related XML Attributes:

Returns
int

getHaloTintList

public ColorStateList getHaloTintList ()

Returns the color of the halo.

Related XML Attributes:

Returns
ColorStateList

getLabelBehavior

public int getLabelBehavior ()

Returns the ERROR(/LabelBehavior) used.

Related XML Attributes:

Returns
int

getMinSeparation

public float getMinSeparation ()

Returns the minimum separation between two thumbs

Related XML Attributes:

Returns
float

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.

Related XML Attributes:

Returns
float

See also:

getThumbElevation

public float getThumbElevation ()

Returns the elevation of the thumb.

Related XML Attributes:

Returns
float

getThumbRadius

public int getThumbRadius ()

Returns the radius of the thumb.

Related XML Attributes:

Returns
int

getThumbStrokeColor

public ColorStateList getThumbStrokeColor ()

Gets the stroke color for the thumb.

Related XML Attributes:

Returns
ColorStateList The color used for the stroke in the thumb.

getThumbStrokeWidth

public float getThumbStrokeWidth ()

Gets the stroke width for the thumb

Related XML Attributes:

Returns
float Stroke width for the thumb.

getThumbTintList

public ColorStateList getThumbTintList ()

Returns the color of the thumb.

Related XML Attributes:

Returns
ColorStateList

getTickActiveTintList

public ColorStateList getTickActiveTintList ()

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

Related XML Attributes:

Returns
ColorStateList

getTickInactiveTintList

public ColorStateList getTickInactiveTintList ()

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

Related XML Attributes:

Returns
ColorStateList

getTickTintList

public ColorStateList getTickTintList ()

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

Related XML Attributes:

Returns
ColorStateList

Throws
IllegalStateException If tickColorActive and tickColorInactive have been set to different values.

getTrackActiveTintList

public ColorStateList getTrackActiveTintList ()

Returns the color of the active portion of the track.

Related XML Attributes:

Returns
ColorStateList

getTrackHeight

public int getTrackHeight ()

Returns the height of the track in pixels.

Related XML Attributes:

Returns
int

getTrackInactiveTintList

public ColorStateList getTrackInactiveTintList ()

Returns the color of the inactive portion of the track.

Related XML Attributes:

Returns
ColorStateList

getTrackSidePadding

public int getTrackSidePadding ()

Returns the side padding of the track.

Returns
int

getTrackTintList

public ColorStateList getTrackTintList ()

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

Related XML Attributes:

Returns
ColorStateList

Throws
IllegalStateException If trackColorActive and trackColorInactive have been set to different values.

getTrackWidth

public int getTrackWidth ()

Returns the width of the track in pixels.

Returns
int

getValueFrom

public float getValueFrom ()

Returns the slider's valueFrom value.

Related XML Attributes:

Returns
float

getValueTo

public float getValueTo ()

Returns the slider's valueTo value.

Related XML Attributes:

Returns
float

See also:

getValues

public List<Float> getValues ()

Returns current values of the slider thumbs.

Returns
List<Float>

hasLabelFormatter

public boolean hasLabelFormatter ()

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

Returns
boolean

isTickVisible

public boolean isTickVisible ()

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

Related XML Attributes:

Returns
boolean

onKeyDown

public boolean onKeyDown (int keyCode, 
                KeyEvent event)

Parameters
keyCode int

event KeyEvent

Returns
boolean

onKeyUp

public boolean onKeyUp (int keyCode, 
                KeyEvent event)

Parameters
keyCode int

event KeyEvent

Returns
boolean

onSaveInstanceState

public Parcelable onSaveInstanceState ()

Returns
Parcelable

onTouchEvent

public boolean onTouchEvent (MotionEvent event)

Parameters
event MotionEvent

Returns
boolean

removeOnChangeListener

public void removeOnChangeListener (L listener)

Removes a callback for value changes from this slider.

Parameters
listener L: 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
listener T: The callback that'll stop be notified when the slider is being touched

setEnabled

public void setEnabled (boolean enabled)

Parameters
enabled boolean

setFocusedThumbIndex

public void setFocusedThumbIndex (int index)

Sets the index of the currently focused thumb

Parameters
index int

setHaloRadius

public void setHaloRadius (int radius)

Sets the radius of the halo in pixels.

Related XML Attributes:

Parameters
radius int

See also:

setHaloRadiusResource

public void setHaloRadiusResource (int radius)

Sets the radius of the halo from a dimension resource.

Related XML Attributes:

Parameters
radius int

See also:

setHaloTintList

public void setHaloTintList (ColorStateList haloColor)

Sets the color of the halo.

Related XML Attributes:

Parameters
haloColor ColorStateList

See also:

setLabelBehavior

public void setLabelBehavior (int labelBehavior)

Determines the ERROR(/LabelBehavior) used.

Related XML Attributes:

Parameters
labelBehavior int

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
formatter LabelFormatter: The LabelFormatter to use to format the bubble's text

setMinSeparation

public void setMinSeparation (float minSeparation)

Sets the minimum separation between two thumbs

Related XML Attributes:

Parameters
minSeparation float

See also:

setMinSeparationValue

public void setMinSeparationValue (float minSeparation)

Sets the minimum separation in the value scale. Useful to create minimum ranges, between thumbs.

Related XML Attributes:

Parameters
minSeparation float

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.

Related XML Attributes:

Parameters
stepSize float: 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
IllegalArgumentException If the step size is less than 0

See also:

setThumbElevation

public void setThumbElevation (float elevation)

Sets the elevation of the thumb.

Related XML Attributes:

Parameters
elevation float

setThumbElevationResource

public void setThumbElevationResource (int elevation)

Sets the elevation of the thumb from a dimension resource.

Related XML Attributes:

Parameters
elevation int

setThumbRadius

public void setThumbRadius (int radius)

Sets the radius of the thumb in pixels.

Related XML Attributes:

Parameters
radius int

See also:

setThumbRadiusResource

public void setThumbRadiusResource (int radius)

Sets the radius of the thumb from a dimension resource.

Related XML Attributes:

Parameters
radius int

See also:

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.

Related XML Attributes:

Parameters
thumbStrokeColor ColorStateList: 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.

Related XML Attributes:

Parameters
thumbStrokeColorResourceId int: 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.

Related XML Attributes:

Parameters
thumbStrokeWidth float: 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.

Related XML Attributes:

Parameters
thumbStrokeWidthResourceId int: Stroke width dimension resource for the thumb

setThumbTintList

public void setThumbTintList (ColorStateList thumbColor)

Sets the color of the thumb.

Related XML Attributes:

Parameters
thumbColor ColorStateList

See also:

setTickActiveTintList

public void setTickActiveTintList (ColorStateList tickColor)

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

Related XML Attributes:

Parameters
tickColor ColorStateList

setTickInactiveTintList

public void setTickInactiveTintList (ColorStateList tickColor)

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

Related XML Attributes:

Parameters
tickColor ColorStateList

setTickTintList

public void setTickTintList (ColorStateList tickColor)

Sets the color of the tick marks.

Related XML Attributes:

Parameters
tickColor ColorStateList

setTickVisible

public void setTickVisible (boolean tickVisible)

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

Related XML Attributes:

Parameters
tickVisible boolean: The visibility of tick marks.

setTrackActiveTintList

public void setTrackActiveTintList (ColorStateList trackColor)

Sets the color of the active portion of the track.

Related XML Attributes:

Parameters
trackColor ColorStateList

setTrackHeight

public void setTrackHeight (int trackHeight)

Set the height of the track in pixels.

Related XML Attributes:

Parameters
trackHeight int

See also:

setTrackInactiveTintList

public void setTrackInactiveTintList (ColorStateList trackColor)

Sets the color of the inactive portion of the track.

Related XML Attributes:

Parameters
trackColor ColorStateList

setTrackTintList

public void setTrackTintList (ColorStateList trackColor)

Sets the color of the track.

Related XML Attributes:

Parameters
trackColor ColorStateList

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.

Related XML Attributes:

Parameters
valueFrom float: The minimum value for the slider's range of values

See also:

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.

Related XML Attributes:

Parameters
valueTo float: The maximum value for the slider's range of values

See also:

setValues

public void setValues (List<Float> values)

Sets multiple values for the slider. Each value will represent a different thumb.

Each 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 values 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.

Parameters
values List: An array of values to set.

See also:

setValues

public void setValues (Float... values)

Sets multiple values for the slider. Each value will represent a different thumb.

Each 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 values 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.

Parameters
values Float: An array of values to set.

See also:

Protected methods

drawableStateChanged

protected void drawableStateChanged ()

onAttachedToWindow

protected void onAttachedToWindow ()

onDetachedFromWindow

protected void onDetachedFromWindow ()

onDraw

protected void onDraw (Canvas canvas)

Parameters
canvas Canvas

onFocusChanged

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

Parameters
gainFocus boolean

direction int

previouslyFocusedRect Rect

onMeasure

protected void onMeasure (int widthMeasureSpec, 
                int heightMeasureSpec)

Parameters
widthMeasureSpec int

heightMeasureSpec int

onRestoreInstanceState

protected void onRestoreInstanceState (Parcelable state)

Parameters
state Parcelable

onSizeChanged

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

Parameters
w int

h int

oldw int

oldh int

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.

Returns
boolean

setActiveThumbIndex

protected void setActiveThumbIndex (int index)

Parameters
index int

setSeparationUnit

protected void setSeparationUnit (int separationUnit)

Parameters
separationUnit int