lightbulb_outline Help shape the future of the Google Play Console, Android Studio, and Firebase. Start survey

AbsSeekBar

public abstract class AbsSeekBar
extends ProgressBar

java.lang.Object
   ↳ android.view.View
     ↳ android.widget.ProgressBar
       ↳ android.widget.AbsSeekBar


AbsSeekBar extends the capabilities of ProgressBar by adding a draggable thumb.

Summary

XML attributes

android:thumbTint Tint to apply to the thumb drawable. 
android:thumbTintMode Blending mode used to apply the thumb tint. 
android:tickMarkTint Tint to apply to the tick mark drawable. 
android:tickMarkTintMode Blending mode used to apply the tick mark tint. 

Inherited XML attributes

Inherited constants

Inherited fields

Public constructors

AbsSeekBar(Context context)
AbsSeekBar(Context context, AttributeSet attrs)
AbsSeekBar(Context context, AttributeSet attrs, int defStyleAttr)
AbsSeekBar(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)

Public methods

void drawableHotspotChanged(float x, float y)

This function is called whenever the view hotspot changes and needs to be propagated to drawables or child views managed by the view.

CharSequence getAccessibilityClassName()

Return the class name of this object to be used for accessibility purposes.

int getKeyProgressIncrement()

Returns the amount of progress changed via the arrow keys.

boolean getSplitTrack()

Returns whether the track should be split by the thumb.

Drawable getThumb()

Return the drawable used to represent the scroll thumb - the component that the user can drag back and forth indicating the current value by its position.

int getThumbOffset()
ColorStateList getThumbTintList()

Returns the tint applied to the thumb drawable, if specified.

PorterDuff.Mode getThumbTintMode()

Returns the blending mode used to apply the tint to the thumb drawable, if specified.

Drawable getTickMark()
ColorStateList getTickMarkTintList()

Returns the tint applied to the tick mark drawable, if specified.

PorterDuff.Mode getTickMarkTintMode()

Returns the blending mode used to apply the tint to the tick mark drawable, if specified.

void jumpDrawablesToCurrentState()

Call Drawable.jumpToCurrentState() on all Drawable objects associated with this view.

boolean onKeyDown(int keyCode, KeyEvent event)

Default implementation of KeyEvent.Callback.onKeyDown(): perform press of the view when KeyEvent.KEYCODE_DPAD_CENTER or KeyEvent.KEYCODE_ENTER is released, if the view is enabled and clickable.

void onRtlPropertiesChanged(int layoutDirection)

Called when any RTL property (layout direction or text direction or text alignment) has been changed.

boolean onTouchEvent(MotionEvent event)

Implement this method to handle touch screen motion events.

void setKeyProgressIncrement(int increment)

Sets the amount of progress changed via the arrow keys.

void setMax(int max)

Set the upper range of the progress bar max.

void setMin(int min)

Set the lower range of the progress bar to min.

void setSplitTrack(boolean splitTrack)

Specifies whether the track should be split by the thumb.

void setThumb(Drawable thumb)

Sets the thumb that will be drawn at the end of the progress meter within the SeekBar.

void setThumbOffset(int thumbOffset)

Sets the thumb offset that allows the thumb to extend out of the range of the track.

void setThumbTintList(ColorStateList tint)

Applies a tint to the thumb drawable.

void setThumbTintMode(PorterDuff.Mode tintMode)

Specifies the blending mode used to apply the tint specified by setThumbTintList(ColorStateList)} to the thumb drawable.

void setTickMark(Drawable tickMark)

Sets the drawable displayed at each progress position, e.g.

void setTickMarkTintList(ColorStateList tint)

Applies a tint to the tick mark drawable.

void setTickMarkTintMode(PorterDuff.Mode tintMode)

Specifies the blending mode used to apply the tint specified by setTickMarkTintList(ColorStateList)} to the tick mark drawable.

Protected methods

void drawableStateChanged()

This function is called whenever the state of the view changes in such a way that it impacts the state of drawables being shown.

void onDraw(Canvas canvas)

Implement this to do your drawing.

void onMeasure(int widthMeasureSpec, int heightMeasureSpec)

Measure the view and its content to determine the measured width and the measured height.

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

This is called during layout when the size of this view has changed.

boolean verifyDrawable(Drawable who)

If your view subclass is displaying its own Drawable objects, it should override this function and return true for any Drawable it is displaying.

Inherited methods

XML attributes

android:thumbTint

Tint to apply to the thumb drawable.

May be a color value, in the form of "#rgb", "#argb", "#rrggbb", or "#aarrggbb".

Related methods:

android:thumbTintMode

Blending mode used to apply the thumb tint.

Must be one of the following constant values.

ConstantValueDescription
add10Combines the tint and drawable color and alpha channels, clamping the result to valid color values. Saturate(S + D)
multiplyeMultiplies the color and alpha channels of the drawable with those of the tint. [Sa * Da, Sc * Dc]
screenf[Sa + Da - Sa * Da, Sc + Dc - Sc * Dc]
src_atop9The tint is drawn above the drawable, but with the drawable’s alpha channel masking the result. [Da, Sc * Da + (1 - Sa) * Dc]
src_in5The tint is masked by the alpha channel of the drawable. The drawable’s color channels are thrown out. [Sa * Da, Sc * Da]
src_over3The tint is drawn on top of the drawable. [Sa + (1 - Sa)*Da, Rc = Sc + (1 - Sa)*Dc]

Related methods:

android:tickMarkTint

Tint to apply to the tick mark drawable.

May be a color value, in the form of "#rgb", "#argb", "#rrggbb", or "#aarrggbb".

Related methods:

android:tickMarkTintMode

Blending mode used to apply the tick mark tint.

Must be one of the following constant values.

ConstantValueDescription
add10Combines the tint and drawable color and alpha channels, clamping the result to valid color values. Saturate(S + D)
multiplyeMultiplies the color and alpha channels of the drawable with those of the tint. [Sa * Da, Sc * Dc]
screenf[Sa + Da - Sa * Da, Sc + Dc - Sc * Dc]
src_atop9The tint is drawn above the drawable, but with the drawable’s alpha channel masking the result. [Da, Sc * Da + (1 - Sa) * Dc]
src_in5The tint is masked by the alpha channel of the drawable. The drawable’s color channels are thrown out. [Sa * Da, Sc * Da]
src_over3The tint is drawn on top of the drawable. [Sa + (1 - Sa)*Da, Rc = Sc + (1 - Sa)*Dc]

Related methods:

Public constructors

AbsSeekBar

added in API level 1
public AbsSeekBar (Context context)

Parameters
context Context

AbsSeekBar

added in API level 1
public AbsSeekBar (Context context, 
                AttributeSet attrs)

Parameters
context Context

attrs AttributeSet

AbsSeekBar

added in API level 1
public AbsSeekBar (Context context, 
                AttributeSet attrs, 
                int defStyleAttr)

Parameters
context Context

attrs AttributeSet

defStyleAttr int

AbsSeekBar

added in API level 21
public AbsSeekBar (Context context, 
                AttributeSet attrs, 
                int defStyleAttr, 
                int defStyleRes)

Parameters
context Context

attrs AttributeSet

defStyleAttr int

defStyleRes int

Public methods

drawableHotspotChanged

added in API level 21
public void drawableHotspotChanged (float x, 
                float y)

This function is called whenever the view hotspot changes and needs to be propagated to drawables or child views managed by the view.

Dispatching to child views is handled by dispatchDrawableHotspotChanged(float, float).

Be sure to call through to the superclass when overriding this function.

Parameters
x float: hotspot x coordinate

y float: hotspot y coordinate

getAccessibilityClassName

added in API level 23
public CharSequence getAccessibilityClassName ()

Return the class name of this object to be used for accessibility purposes. Subclasses should only override this if they are implementing something that should be seen as a completely new class of view when used by accessibility, unrelated to the class it is deriving from. This is used to fill in AccessibilityNodeInfo.setClassName.

Returns
CharSequence

getKeyProgressIncrement

added in API level 3
public int getKeyProgressIncrement ()

Returns the amount of progress changed via the arrow keys.

By default, this will be a value that is derived from the progress range.

Returns
int The amount to increment or decrement when the user presses the arrow keys. This will be positive.

getSplitTrack

added in API level 21
public boolean getSplitTrack ()

Returns whether the track should be split by the thumb.

Returns
boolean

getThumb

added in API level 16
public Drawable getThumb ()

Return the drawable used to represent the scroll thumb - the component that the user can drag back and forth indicating the current value by its position.

Returns
Drawable The current thumb drawable

getThumbOffset

added in API level 1
public int getThumbOffset ()

Returns
int

getThumbTintList

added in API level 21
public ColorStateList getThumbTintList ()

Returns the tint applied to the thumb drawable, if specified.

Related XML Attributes:

Returns
ColorStateList the tint applied to the thumb drawable

This value may be null.

getThumbTintMode

added in API level 21
public PorterDuff.Mode getThumbTintMode ()

Returns the blending mode used to apply the tint to the thumb drawable, if specified.

Related XML Attributes:

Returns
PorterDuff.Mode the blending mode used to apply the tint to the thumb drawable

This value may be null.

getTickMark

added in API level 24
public Drawable getTickMark ()

Returns
Drawable the drawable displayed at each progress position

getTickMarkTintList

added in API level 24
public ColorStateList getTickMarkTintList ()

Returns the tint applied to the tick mark drawable, if specified.

Related XML Attributes:

Returns
ColorStateList the tint applied to the tick mark drawable

This value may be null.

getTickMarkTintMode

added in API level 24
public PorterDuff.Mode getTickMarkTintMode ()

Returns the blending mode used to apply the tint to the tick mark drawable, if specified.

Related XML Attributes:

Returns
PorterDuff.Mode the blending mode used to apply the tint to the tick mark drawable

This value may be null.

jumpDrawablesToCurrentState

added in API level 11
public void jumpDrawablesToCurrentState ()

Call Drawable.jumpToCurrentState() on all Drawable objects associated with this view.

Also calls StateListAnimator.jumpToCurrentState() if there is a StateListAnimator attached to this view.

onKeyDown

added in API level 1
public boolean onKeyDown (int keyCode, 
                KeyEvent event)

Default implementation of KeyEvent.Callback.onKeyDown(): perform press of the view when KeyEvent.KEYCODE_DPAD_CENTER or KeyEvent.KEYCODE_ENTER is released, if the view is enabled and clickable.

Key presses in software keyboards will generally NOT trigger this listener, although some may elect to do so in some situations. Do not rely on this to catch software key presses.

Parameters
keyCode int: a key code that represents the button pressed, from KeyEvent

event KeyEvent: the KeyEvent object that defines the button action

Returns
boolean If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false.

onRtlPropertiesChanged

added in API level 17
public void onRtlPropertiesChanged (int layoutDirection)

Called when any RTL property (layout direction or text direction or text alignment) has been changed. Subclasses need to override this method to take care of cached information that depends on the resolved layout direction, or to inform child views that inherit their layout direction. The default implementation does nothing.

Parameters
layoutDirection int: the direction of the layout

onTouchEvent

added in API level 1
public boolean onTouchEvent (MotionEvent event)

Implement this method to handle touch screen motion events.

If this method is used to detect click actions, it is recommended that the actions be performed by implementing and calling performClick(). This will ensure consistent system behavior, including:

  • obeying click sound preferences
  • dispatching OnClickListener calls
  • handling ACTION_CLICK when accessibility features are enabled

Parameters
event MotionEvent: The motion event.

Returns
boolean True if the event was handled, false otherwise.

setKeyProgressIncrement

added in API level 3
public void setKeyProgressIncrement (int increment)

Sets the amount of progress changed via the arrow keys.

Parameters
increment int: The amount to increment or decrement when the user presses the arrow keys.

setMax

added in API level 1
public void setMax (int max)

Set the upper range of the progress bar max.

Parameters
max int: the upper range of this progress bar

setMin

added in API level 26
public void setMin (int min)

Set the lower range of the progress bar to min.

Parameters
min int: the lower range of this progress bar

setSplitTrack

added in API level 21
public void setSplitTrack (boolean splitTrack)

Specifies whether the track should be split by the thumb. When true, the thumb's optical bounds will be clipped out of the track drawable, then the thumb will be drawn into the resulting gap.

Parameters
splitTrack boolean: Whether the track should be split by the thumb

setThumb

added in API level 1
public void setThumb (Drawable thumb)

Sets the thumb that will be drawn at the end of the progress meter within the SeekBar.

If the thumb is a valid drawable (i.e. not null), half its width will be used as the new thumb offset (@see #setThumbOffset(int)).

Parameters
thumb Drawable: Drawable representing the thumb

setThumbOffset

added in API level 1
public void setThumbOffset (int thumbOffset)

Sets the thumb offset that allows the thumb to extend out of the range of the track.

Parameters
thumbOffset int: The offset amount in pixels.

setThumbTintList

added in API level 21
public void setThumbTintList (ColorStateList tint)

Applies a tint to the thumb drawable. Does not modify the current tint mode, which is PorterDuff.Mode.SRC_IN by default.

Subsequent calls to setThumb(Drawable) will automatically mutate the drawable and apply the specified tint and tint mode using Drawable.setTintList(ColorStateList).

Related XML Attributes:

Parameters
tint ColorStateList: the tint to apply, may be null to clear tint

setThumbTintMode

added in API level 21
public void setThumbTintMode (PorterDuff.Mode tintMode)

Specifies the blending mode used to apply the tint specified by setThumbTintList(ColorStateList)} to the thumb drawable. The default mode is PorterDuff.Mode.SRC_IN.

Related XML Attributes:

Parameters
tintMode PorterDuff.Mode: the blending mode used to apply the tint, may be null to clear tint

setTickMark

added in API level 24
public void setTickMark (Drawable tickMark)

Sets the drawable displayed at each progress position, e.g. at each possible thumb position.

Parameters
tickMark Drawable: the drawable to display at each progress position

setTickMarkTintList

added in API level 24
public void setTickMarkTintList (ColorStateList tint)

Applies a tint to the tick mark drawable. Does not modify the current tint mode, which is PorterDuff.Mode.SRC_IN by default.

Subsequent calls to setTickMark(Drawable) will automatically mutate the drawable and apply the specified tint and tint mode using Drawable.setTintList(ColorStateList).

Related XML Attributes:

Parameters
tint ColorStateList: the tint to apply, may be null to clear tint

setTickMarkTintMode

added in API level 24
public void setTickMarkTintMode (PorterDuff.Mode tintMode)

Specifies the blending mode used to apply the tint specified by setTickMarkTintList(ColorStateList)} to the tick mark drawable. The default mode is PorterDuff.Mode.SRC_IN.

Related XML Attributes:

Parameters
tintMode PorterDuff.Mode: the blending mode used to apply the tint, may be null to clear tint

Protected methods

drawableStateChanged

added in API level 1
protected void drawableStateChanged ()

This function is called whenever the state of the view changes in such a way that it impacts the state of drawables being shown.

If the View has a StateListAnimator, it will also be called to run necessary state change animations.

Be sure to call through to the superclass when overriding this function.

onDraw

added in API level 1
protected void onDraw (Canvas canvas)

Implement this to do your drawing.

Parameters
canvas Canvas: the canvas on which the background will be drawn

onMeasure

added in API level 1
protected void onMeasure (int widthMeasureSpec, 
                int heightMeasureSpec)

Measure the view and its content to determine the measured width and the measured height. This method is invoked by measure(int, int) and should be overridden by subclasses to provide accurate and efficient measurement of their contents.

CONTRACT: When overriding this method, you must call setMeasuredDimension(int, int) to store the measured width and height of this view. Failure to do so will trigger an IllegalStateException, thrown by measure(int, int). Calling the superclass' onMeasure(int, int) is a valid use.

The base class implementation of measure defaults to the background size, unless a larger size is allowed by the MeasureSpec. Subclasses should override onMeasure(int, int) to provide better measurements of their content.

If this method is overridden, it is the subclass's responsibility to make sure the measured height and width are at least the view's minimum height and width (getSuggestedMinimumHeight() and getSuggestedMinimumWidth()).

Parameters
widthMeasureSpec int: horizontal space requirements as imposed by the parent. The requirements are encoded with View.MeasureSpec.

heightMeasureSpec int: vertical space requirements as imposed by the parent. The requirements are encoded with View.MeasureSpec.

onSizeChanged

added in API level 1
protected void onSizeChanged (int w, 
                int h, 
                int oldw, 
                int oldh)

This is called during layout when the size of this view has changed. If you were just added to the view hierarchy, you're called with the old values of 0.

Parameters
w int: Current width of this view.

h int: Current height of this view.

oldw int: Old width of this view.

oldh int: Old height of this view.

verifyDrawable

added in API level 1
protected boolean verifyDrawable (Drawable who)

If your view subclass is displaying its own Drawable objects, it should override this function and return true for any Drawable it is displaying. This allows animations for those drawables to be scheduled.

Be sure to call through to the super class when overriding this function.

Parameters
who Drawable: The Drawable to verify. Return true if it is one you are displaying, else return the result of calling through to the super class.

This value must never be null.

Returns
boolean boolean If true than the Drawable is being displayed in the view; else false and it is not allowed to animate.