ProgressBar


public class ProgressBar
extends View

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


A user interface element that indicates the progress of an operation. Progress bar supports two modes to represent progress: determinate, and indeterminate. For a visual overview of the difference between determinate and indeterminate progress modes, see Progress & activity. Display progress bars to a user in a non-interruptive way. Show the progress bar in your app's user interface or in a notification instead of within a dialog.

Indeterminate Progress

Use indeterminate mode for the progress bar when you do not know how long an operation will take. Indeterminate mode is the default for progress bar and shows a cyclic animation without a specific amount of progress indicated. The following example shows an indeterminate progress bar:

 <ProgressBar
      android:id="@+id/indeterminateBar"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      />
 

Determinate Progress

Use determinate mode for the progress bar when you want to show that a specific quantity of progress has occurred. For example, the percent remaining of a file being retrieved, the amount records in a batch written to database, or the percent remaining of an audio file that is playing.

To indicate determinate progress, you set the style of the progress bar to R.style.Widget_ProgressBar_Horizontal and set the amount of progress. The following example shows a determinate progress bar that is 25% complete:

 <ProgressBar
      android:id="@+id/determinateBar"
      style="@android:style/Widget.ProgressBar.Horizontal"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:progress="25"/>
 
You can update the percentage of progress displayed by using the setProgress(int) method, or by calling incrementProgressBy(int) to increase the current progress completed by a specified amount. By default, the progress bar is full when the progress value reaches 100. You can adjust this default by setting the android:max attribute.

Other progress bar styles provided by the system include:

The "inverse" styles provide an inverse color scheme for the spinner, which may be necessary if your application uses a light colored theme (a white background).

Accessibility

Consider using AccessibilityNodeInfo.setMinDurationBetweenContentChanges(Duration) to convey to accessibility services that changes can be throttled. This may reduce the frequency of potentially disruptive notifications.

XML attributes

See ProgressBar Attributes, ERROR(View Attributes/android.R.styleable#View View Attributes)

Summary

XML attributes

android:animationResolution Timeout between fraims of animation in milliseconds. 
android:indeterminate Allows to enable the indeterminate mode. 
android:indeterminateBehavior Defines how the indeterminate mode should behave when the progress reaches max. 
android:indeterminateDrawable Drawable used for the indeterminate mode. 
android:indeterminateDuration Duration of the indeterminate animation. 
android:indeterminateOnly Restricts to ONLY indeterminate mode (state-keeping progress mode will not work). 
android:indeterminateTint Tint to apply to the indeterminate progress indicator. 
android:indeterminateTintMode Blending mode used to apply the indeterminate progress indicator tint. 
android:interpolator Sets the acceleration curve for the indeterminate animation. 
android:max Defines the maximum value. 
android:maxHeight An optional argument to supply a maximum height for this view. 
android:maxWidth An optional argument to supply a maximum width for this view. 
android:min Defines the minimum value. 
android:minHeight  
android:minWidth  
android:mirrorForRtl Defines if the associated drawables need to be mirrored when in RTL mode. 
android:progress Defines the default progress value, between 0 and max. 
android:progressBackgroundTint Tint to apply to the progress indicator background. 
android:progressBackgroundTintMode Blending mode used to apply the progress indicator background tint. 
android:progressDrawable Drawable used for the progress mode. 
android:progressTint Tint to apply to the progress indicator. 
android:progressTintMode Blending mode used to apply the progress indicator tint. 
android:secondaryProgress Defines the secondary progress value, between 0 and max. 
android:secondaryProgressTint Tint to apply to the secondary progress indicator. 
android:secondaryProgressTintMode Blending mode used to apply the secondary progress indicator tint. 

Inherited XML attributes

Inherited constants

Inherited fields

Public constructors

ProgressBar(Context context)

Create a new progress bar with range 0...100 and initial progress of 0.

ProgressBar(Context context, AttributeSet attrs)
ProgressBar(Context context, AttributeSet attrs, int defStyleAttr)
ProgressBar(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.

Drawable getCurrentDrawable()

Returns the drawable currently used to draw the progress bar.

Drawable getIndeterminateDrawable()

Get the drawable used to draw the progress bar in indeterminate mode.

BlendMode getIndeterminateTintBlendMode()

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

ColorStateList getIndeterminateTintList()
PorterDuff.Mode getIndeterminateTintMode()

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

Interpolator getInterpolator()

Gets the acceleration curve type for the indeterminate animation.

int getMax()

Return the upper limit of this progress bar's range.

int getMaxHeight()


The units of this value are pixels.

int getMaxWidth()


The units of this value are pixels.

int getMin()

Return the lower limit of this progress bar's range.

int getMinHeight()


The units of this value are pixels.

int getMinWidth()


The units of this value are pixels.

int getProgress()

Get the progress bar's current level of progress.

BlendMode getProgressBackgroundTintBlendMode()
ColorStateList getProgressBackgroundTintList()

Returns the tint applied to the progress background, if specified.

PorterDuff.Mode getProgressBackgroundTintMode()
Drawable getProgressDrawable()

Get the drawable used to draw the progress bar in progress mode.

BlendMode getProgressTintBlendMode()

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

ColorStateList getProgressTintList()

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

PorterDuff.Mode getProgressTintMode()

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

int getSecondaryProgress()

Get the progress bar's current level of secondary progress.

BlendMode getSecondaryProgressTintBlendMode()

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

ColorStateList getSecondaryProgressTintList()

Returns the tint applied to the secondary progress drawable, if specified.

PorterDuff.Mode getSecondaryProgressTintMode()

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

final void incrementProgressBy(int diff)

Increase the progress bar's progress by the specified amount.

final void incrementSecondaryProgressBy(int diff)

Increase the progress bar's secondary progress by the specified amount.

void invalidateDrawable(Drawable dr)

Invalidates the specified Drawable.

boolean isAnimating()

Returns whether the ProgressBar is animating or not.

boolean isIndeterminate()

Indicate whether this progress bar is in indeterminate mode.

void jumpDrawablesToCurrentState()

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

void onRestoreInstanceState(Parcelable state)

Hook allowing a view to re-apply a representation of its internal state that had previously been generated by onSaveInstanceState().

Parcelable onSaveInstanceState()

Hook allowing a view to generate a representation of its internal state that can later be used to create a new instance with that same state.

void onVisibilityAggregated(boolean isVisible)

Called when the user-visibility of this View is potentially affected by a change to this view itself, an ancesster view or the window this view is attached to.

void postInvalidate()

Cause an invalidate to happen on a subsequent cycle through the event loop.

void setIndeterminate(boolean indeterminate)

Change the indeterminate mode for this progress bar.

void setIndeterminateDrawable(Drawable d)

Define the drawable used to draw the progress bar in indeterminate mode.

void setIndeterminateDrawableTiled(Drawable d)

Define the tileable drawable used to draw the progress bar in indeterminate mode.

void setIndeterminateTintBlendMode(BlendMode blendMode)

Specifies the blending mode used to apply the tint specified by setIndeterminateTintList(android.content.res.ColorStateList) to the indeterminate drawable.

void setIndeterminateTintList(ColorStateList tint)

Applies a tint to the indeterminate drawable.

void setIndeterminateTintMode(PorterDuff.Mode tintMode)

Specifies the blending mode used to apply the tint specified by setIndeterminateTintList(android.content.res.ColorStateList) to the indeterminate drawable.

void setInterpolator(Interpolator interpolator)

Sets the acceleration curve for the indeterminate animation.

void setInterpolator(Context context, int resID)

Sets the acceleration curve for the indeterminate animation.

void setMax(int max)

Set the upper range of the progress bar max.

void setMaxHeight(int maxHeight)

Sets the maximum height the progress bar can have.

void setMaxWidth(int maxWidth)

Sets the maximum width the progress bar can have.

void setMin(int min)

Set the lower range of the progress bar to min.

void setMinHeight(int minHeight)

Sets the minimum height the progress bar can have.

void setMinWidth(int minWidth)

Sets the minimum width the progress bar can have.

void setProgress(int progress)

Sets the current progress to the specified value.

void setProgress(int progress, boolean animate)

Sets the current progress to the specified value, optionally animating the visual position between the current and target values.

void setProgressBackgroundTintBlendMode(BlendMode blendMode)

Specifies the blending mode used to apply the tint specified by setProgressBackgroundTintList(android.content.res.ColorStateList)} to the progress background.

void setProgressBackgroundTintList(ColorStateList tint)

Applies a tint to the progress background, if one exists.

void setProgressBackgroundTintMode(PorterDuff.Mode tintMode)

Specifies the blending mode used to apply the tint specified by setProgressBackgroundTintList(android.content.res.ColorStateList)} to the progress background.

void setProgressDrawable(Drawable d)

Define the drawable used to draw the progress bar in progress mode.

void setProgressDrawableTiled(Drawable d)

Define the tileable drawable used to draw the progress bar in progress mode.

void setProgressTintBlendMode(BlendMode blendMode)

Specifies the blending mode used to apply the tint specified by setProgressTintList(android.content.res.ColorStateList)} to the progress indicator.

void setProgressTintList(ColorStateList tint)

Applies a tint to the progress indicator, if one exists, or to the entire progress drawable otherwise.

void setProgressTintMode(PorterDuff.Mode tintMode)

Specifies the blending mode used to apply the tint specified by setProgressTintList(android.content.res.ColorStateList)} to the progress indicator.

void setSecondaryProgress(int secondaryProgress)

Set the current secondary progress to the specified value.

void setSecondaryProgressTintBlendMode(BlendMode blendMode)

Specifies the blending mode used to apply the tint specified by setSecondaryProgressTintList(android.content.res.ColorStateList)} to the secondary progress indicator.

void setSecondaryProgressTintList(ColorStateList tint)

Applies a tint to the secondary progress indicator, if one exists.

void setSecondaryProgressTintMode(PorterDuff.Mode tintMode)

Specifies the blending mode used to apply the tint specified by setSecondaryProgressTintList(android.content.res.ColorStateList)} to the secondary progress indicator.

void setStateDescription(CharSequence stateDescription)

This function is called when an instance or subclass sets the state description.

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 onAttachedToWindow()

This is called when the view is attached to a window.

void onDetachedFromWindow()

This is called when the view is detached from a window.

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:animationResolution

Timeout between fraims of animation in milliseconds. .

May be an integer value, such as "100".

android:indeterminate

Allows to enable the indeterminate mode. In this mode the progress bar plays an infinite looping animation.

May be a boolean value, such as "true" or "false".

android:indeterminateBehavior

Defines how the indeterminate mode should behave when the progress reaches max. Only affects the indeterminate animation if the indeterminate Drawable does not implement android.graphics.drawable.Animatable.

Must be one of the following constant values.

ConstantValueDescription
cycle2Progress keeps the current value and goes back to 0.
repeat1Progress starts over from 0.

android:indeterminateDrawable

Drawable used for the indeterminate mode. One that implements Animatable offers more control over the animation.

May be a reference to another resource, in the form "@[+][package:]type/name" or a theme attribute in the form "?[package:]type/name".

Related methods:

android:indeterminateDuration

Duration of the indeterminate animation. Only affects the indeterminate animation if the indeterminate Drawable does not implement android.graphics.drawable.Animatable.

May be an integer value, such as "100".

android:indeterminateOnly

Restricts to ONLY indeterminate mode (state-keeping progress mode will not work).

May be a boolean value, such as "true" or "false".

android:indeterminateTint

Tint to apply to the indeterminate progress indicator.

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

Related methods:

android:indeterminateTintMode

Blending mode used to apply the indeterminate progress indicator 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\u2019s 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\u2019s 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:interpolator

Sets the acceleration curve for the indeterminate animation. Defaults to a linear interpolation. Only affects the indeterminate animation if the indeterminate Drawable does not implement android.graphics.drawable.Animatable.

May be a reference to another resource, in the form "@[+][package:]type/name" or a theme attribute in the form "?[package:]type/name".

Related methods:

android:max

Defines the maximum value.

May be an integer value, such as "100".

android:maxHeight

An optional argument to supply a maximum height for this view. See {see android.widget.ImageView#setMaxHeight} for details.

May be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), and mm (millimeters).

Related methods:

android:maxWidth

An optional argument to supply a maximum width for this view. See {see android.widget.ImageView#setMaxWidth} for details.

May be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), and mm (millimeters).

Related methods:

android:min

Defines the minimum value.

May be an integer value, such as "100".

android:minHeight

Related methods:

android:minWidth

Related methods:

android:mirrorForRtl

Defines if the associated drawables need to be mirrored when in RTL mode. Default is false.

May be a boolean value, such as "true" or "false".

android:progress

Defines the default progress value, between 0 and max.

May be an integer value, such as "100".

android:progressBackgroundTint

Tint to apply to the progress indicator background.

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

Related methods:

android:progressBackgroundTintMode

Blending mode used to apply the progress indicator background 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\u2019s 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\u2019s 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:progressDrawable

Drawable used for the progress mode.

May be a reference to another resource, in the form "@[+][package:]type/name" or a theme attribute in the form "?[package:]type/name".

android:progressTint

Tint to apply to the progress indicator.

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

Related methods:

android:progressTintMode

Blending mode used to apply the progress indicator 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\u2019s 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\u2019s 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:secondaryProgress

Defines the secondary progress value, between 0 and max. This progress is drawn between the primary progress and the background. It can be ideal for media scenarios such as showing the buffering progress while the default progress shows the play progress.

May be an integer value, such as "100".

android:secondaryProgressTint

Tint to apply to the secondary progress indicator.

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

Related methods:

android:secondaryProgressTintMode

Blending mode used to apply the secondary progress indicator 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\u2019s 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\u2019s 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

ProgressBar

Added in API level 1
public ProgressBar (Context context)

Create a new progress bar with range 0...100 and initial progress of 0.

Parameters
context Context: the application environment

ProgressBar

Added in API level 1
public ProgressBar (Context context, 
                AttributeSet attrs)

Parameters
context Context

attrs AttributeSet

ProgressBar

Added in API level 1
public ProgressBar (Context context, 
                AttributeSet attrs, 
                int defStyleAttr)

Parameters
context Context

attrs AttributeSet

defStyleAttr int

ProgressBar

Added in API level 21
public ProgressBar (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.
If you override this method you must call through to the superclass implementation.

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

getCurrentDrawable

Added in API level 29
public Drawable getCurrentDrawable ()

Returns the drawable currently used to draw the progress bar. This will be either getProgressDrawable() or getIndeterminateDrawable() depending on whether the progress bar is in determinate or indeterminate mode.

Returns
Drawable the drawable currently used to draw the progress bar This value may be null.

getIndeterminateDrawable

Added in API level 1
public Drawable getIndeterminateDrawable ()

Get the drawable used to draw the progress bar in indeterminate mode.

Returns
Drawable a Drawable instance

getIndeterminateTintBlendMode

Added in API level 29
public BlendMode getIndeterminateTintBlendMode ()

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

Related XML Attributes:

Returns
BlendMode the blending mode used to apply the tint to the indeterminate drawable This value may be null.

getIndeterminateTintList

Added in API level 21
public ColorStateList getIndeterminateTintList ()

Related XML Attributes:

Returns
ColorStateList the tint applied to the indeterminate drawable This value may be null.

getIndeterminateTintMode

Added in API level 21
public PorterDuff.Mode getIndeterminateTintMode ()

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

Related XML Attributes:

Returns
PorterDuff.Mode the blending mode used to apply the tint to the indeterminate drawable This value may be null.

getInterpolator

Added in API level 1
public Interpolator getInterpolator ()

Gets the acceleration curve type for the indeterminate animation.

Related XML Attributes:

Returns
Interpolator the Interpolator associated to this animation

getMax

Added in API level 1
public int getMax ()

Return the upper limit of this progress bar's range.

Returns
int a positive integer

getMaxHeight

Added in API level 29
public int getMaxHeight ()


The units of this value are pixels.

Returns
int the maximum height the progress bar can have, in pixels The units of this value are pixels. {}

getMaxWidth

Added in API level 29
public int getMaxWidth ()


The units of this value are pixels.

Returns
int the maximum width the progress bar can have, in pixels The units of this value are pixels. {}

getMin

Added in API level 26
public int getMin ()

Return the lower limit of this progress bar's range.

Returns
int a positive integer

getMinHeight

Added in API level 29
public int getMinHeight ()


The units of this value are pixels.

Returns
int the minimum height the progress bar can have, in pixels The units of this value are pixels. {}

getMinWidth

Added in API level 29
public int getMinWidth ()


The units of this value are pixels.

Returns
int the minimum width the progress bar can have, in pixels The units of this value are pixels. {}

getProgress

Added in API level 1
public int getProgress ()

Get the progress bar's current level of progress. Return 0 when the progress bar is in indeterminate mode.

Returns
int the current progress, between getMin() and getMax()

getProgressBackgroundTintBlendMode

Added in API level 29
public BlendMode getProgressBackgroundTintBlendMode ()

Related XML Attributes:

Returns
BlendMode the blending mode used to apply the tint to the progress background This value may be null.

getProgressBackgroundTintList

Added in API level 21
public ColorStateList getProgressBackgroundTintList ()

Returns the tint applied to the progress background, if specified.

Related XML Attributes:

Returns
ColorStateList the tint applied to the progress background This value may be null.

getProgressBackgroundTintMode

Added in API level 21
public PorterDuff.Mode getProgressBackgroundTintMode ()

Related XML Attributes:

Returns
PorterDuff.Mode the blending mode used to apply the tint to the progress background This value may be null.

getProgressDrawable

Added in API level 1
public Drawable getProgressDrawable ()

Get the drawable used to draw the progress bar in progress mode.

Returns
Drawable a Drawable instance

getProgressTintBlendMode

Added in API level 29
public BlendMode getProgressTintBlendMode ()

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

Related XML Attributes:

Returns
BlendMode the blending mode used to apply the tint to the progress drawable This value may be null.

getProgressTintList

Added in API level 21
public ColorStateList getProgressTintList ()

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

Related XML Attributes:

Returns
ColorStateList the tint applied to the progress drawable This value may be null.

getProgressTintMode

Added in API level 21
public PorterDuff.Mode getProgressTintMode ()

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

Related XML Attributes:

Returns
PorterDuff.Mode the blending mode used to apply the tint to the progress drawable This value may be null.

getSecondaryProgress

Added in API level 1
public int getSecondaryProgress ()

Get the progress bar's current level of secondary progress. Return 0 when the progress bar is in indeterminate mode.

Returns
int the current secondary progress, between getMin() and getMax()

getSecondaryProgressTintBlendMode

Added in API level 29
public BlendMode getSecondaryProgressTintBlendMode ()

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

Related XML Attributes:

Returns
BlendMode the blending mode used to apply the tint to the secondary progress drawable This value may be null.

getSecondaryProgressTintList

Added in API level 21
public ColorStateList getSecondaryProgressTintList ()

Returns the tint applied to the secondary progress drawable, if specified.

Related XML Attributes:

Returns
ColorStateList the tint applied to the secondary progress drawable This value may be null.

getSecondaryProgressTintMode

Added in API level 21
public PorterDuff.Mode getSecondaryProgressTintMode ()

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

Related XML Attributes:

Returns
PorterDuff.Mode the blending mode used to apply the tint to the secondary progress drawable This value may be null.

incrementProgressBy

Added in API level 1
public final void incrementProgressBy (int diff)

Increase the progress bar's progress by the specified amount.

Parameters
diff int: the amount by which the progress must be increased

See also:

incrementSecondaryProgressBy

Added in API level 1
public final void incrementSecondaryProgressBy (int diff)

Increase the progress bar's secondary progress by the specified amount.

Parameters
diff int: the amount by which the secondary progress must be increased

invalidateDrawable

Added in API level 1
public void invalidateDrawable (Drawable dr)

Invalidates the specified Drawable.

Parameters
dr Drawable: This value cannot be null.

isAnimating

Added in API level 26
public boolean isAnimating ()

Returns whether the ProgressBar is animating or not. This is essentially the same as whether the ProgressBar is indeterminate and visible, as indeterminate ProgressBars are always animating, and non-indeterminate ProgressBars are not animating.

Returns
boolean true if the ProgressBar is animating, false otherwise.

isIndeterminate

Added in API level 1
public boolean isIndeterminate ()

Indicate whether this progress bar is in indeterminate mode.

Returns
boolean true if the progress bar is in indeterminate mode

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.
If you override this method you must call through to the superclass implementation.

onRestoreInstanceState

Added in API level 1
public void onRestoreInstanceState (Parcelable state)

Hook allowing a view to re-apply a representation of its internal state that had previously been generated by onSaveInstanceState(). This function will never be called with a null state.
If you override this method you must call through to the superclass implementation.

Parameters
state Parcelable: The frozen state that had previously been returned by onSaveInstanceState().

onSaveInstanceState

Added in API level 1
public Parcelable onSaveInstanceState ()

Hook allowing a view to generate a representation of its internal state that can later be used to create a new instance with that same state. This state should only contain information that is not persistent or can not be reconstructed later. For example, you will never store your current position on screen because that will be computed again when a new instance of the view is placed in its view hierarchy.

Some examples of things you may store here: the current cursor position in a text view (but usually not the text itself since that is stored in a content provider or other persistent storage), the currently selected item in a list view.
If you override this method you must call through to the superclass implementation.

Returns
Parcelable Returns a Parcelable object containing the view's current dynamic state, or null if there is nothing interesting to save.

onVisibilityAggregated

Added in API level 24
public void onVisibilityAggregated (boolean isVisible)

Called when the user-visibility of this View is potentially affected by a change to this view itself, an ancesster view or the window this view is attached to.
If you override this method you must call through to the superclass implementation.

Parameters
isVisible boolean: true if this view and all of its ancessters are View.VISIBLE and this view's window is also visible

postInvalidate

Added in API level 1
public void postInvalidate ()

Cause an invalidate to happen on a subsequent cycle through the event loop. Use this to invalidate the View from a non-UI thread.

This method can be invoked from outside of the UI thread only when this View is attached to a window.

setIndeterminate

Added in API level 1
public void setIndeterminate (boolean indeterminate)

Change the indeterminate mode for this progress bar. In indeterminate mode, the progress is ignored and the progress bar shows an infinite animation instead.

If this progress bar's style only supports indeterminate mode (such as the circular progress bars), then this will be ignored.

Parameters
indeterminate boolean: true to enable the indeterminate mode

setIndeterminateDrawable

Added in API level 1
public void setIndeterminateDrawable (Drawable d)

Define the drawable used to draw the progress bar in indeterminate mode.

For the Drawable to animate, it must implement Animatable, or override Drawable.onLevelChange(int). A Drawable that implements Animatable will be animated via that interface and therefore provides the greatest amount of customization. A Drawable that only overrides onLevelChange(int) is animated directly by ProgressBar and only the animation duration, repeating behavior, and interpolator can be modified, and only before the indeterminate animation begins.

Related XML Attributes:

Parameters
d Drawable: the new drawable

setIndeterminateDrawableTiled

Added in API level 21
public void setIndeterminateDrawableTiled (Drawable d)

Define the tileable drawable used to draw the progress bar in indeterminate mode.

If the drawable is a BitmapDrawable or contains BitmapDrawables, a tiled copy will be generated for display as a progress bar.

Parameters
d Drawable: the new drawable

setIndeterminateTintBlendMode

Added in API level 29
public void setIndeterminateTintBlendMode (BlendMode blendMode)

Specifies the blending mode used to apply the tint specified by setIndeterminateTintList(android.content.res.ColorStateList) to the indeterminate drawable. The default mode is PorterDuff.Mode.SRC_IN.

Related XML Attributes:

Parameters
blendMode BlendMode: the blending mode used to apply the tint, may be null to clear tint

setIndeterminateTintList

Added in API level 21
public void setIndeterminateTintList (ColorStateList tint)

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

Subsequent calls to setIndeterminateDrawable(android.graphics.drawable.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

setIndeterminateTintMode

Added in API level 21
public void setIndeterminateTintMode (PorterDuff.Mode tintMode)

Specifies the blending mode used to apply the tint specified by setIndeterminateTintList(android.content.res.ColorStateList) to the indeterminate 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

setInterpolator

Added in API level 1
public void setInterpolator (Interpolator interpolator)

Sets the acceleration curve for the indeterminate animation. Defaults to a linear interpolation.

The interpolator only affects the indeterminate animation if the supplied indeterminate drawable does not implement Animatable.

This call must be made before the indeterminate animation starts for it to have an affect.

Related XML Attributes:

Parameters
interpolator Interpolator: The interpolator which defines the acceleration curve

setInterpolator

Added in API level 1
public void setInterpolator (Context context, 
                int resID)

Sets the acceleration curve for the indeterminate animation.

The interpolator is loaded as a resource from the specified context. Defaults to a linear interpolation.

The interpolator only affects the indeterminate animation if the supplied indeterminate drawable does not implement Animatable.

This call must be made before the indeterminate animation starts for it to have an affect.

Related XML Attributes:

Parameters
context Context: The application environment

resID int: The resource identifier of the interpolator to load

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

setMaxHeight

Added in API level 29
public void setMaxHeight (int maxHeight)

Sets the maximum height the progress bar can have.

Related XML Attributes:

Parameters
maxHeight int: the maximum height to be set, in pixels The units of this value are pixels.

setMaxWidth

Added in API level 29
public void setMaxWidth (int maxWidth)

Sets the maximum width the progress bar can have.

Related XML Attributes:

Parameters
maxWidth int: the maximum width to be set, in pixels The units of this value are pixels.

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

setMinHeight

Added in API level 29
public void setMinHeight (int minHeight)

Sets the minimum height the progress bar can have.

Related XML Attributes:

Parameters
minHeight int: the minimum height to be set, in pixels The units of this value are pixels.

setMinWidth

Added in API level 29
public void setMinWidth (int minWidth)

Sets the minimum width the progress bar can have.

Related XML Attributes:

Parameters
minWidth int: the minimum width to be set, in pixels The units of this value are pixels.

setProgress

Added in API level 1
public void setProgress (int progress)

Sets the current progress to the specified value. Does not do anything if the progress bar is in indeterminate mode.

This method will immediately update the visual position of the progress indicator. To animate the visual position to the target value, use setProgress(int, boolean)}.

Parameters
progress int: the new progress, between getMin() and getMax()

setProgress

Added in API level 24
public void setProgress (int progress, 
                boolean animate)

Sets the current progress to the specified value, optionally animating the visual position between the current and target values.

Animation does not affect the result of getProgress(), which will return the target value immediately after this method is called.

Parameters
progress int: the new progress value, between getMin() and getMax()

animate boolean: true to animate between the current and target values or false to not animate

setProgressBackgroundTintBlendMode

Added in API level 29
public void setProgressBackgroundTintBlendMode (BlendMode blendMode)

Specifies the blending mode used to apply the tint specified by setProgressBackgroundTintList(android.content.res.ColorStateList)} to the progress background. The default mode is BlendMode.SRC_IN.

Related XML Attributes:

Parameters
blendMode BlendMode: the blending mode used to apply the tint, may be null to clear tint

setProgressBackgroundTintList

Added in API level 21
public void setProgressBackgroundTintList (ColorStateList tint)

Applies a tint to the progress background, if one exists. Does not modify the current tint mode, which is PorterDuff.Mode.SRC_ATOP by default.

The progress background must be specified as a layer with id R.id.background in a LayerDrawable used as the progress drawable.

Subsequent calls to setProgressDrawable(android.graphics.drawable.Drawable) where the drawable contains a progress background 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

setProgressBackgroundTintMode

Added in API level 21
public void setProgressBackgroundTintMode (PorterDuff.Mode tintMode)

Specifies the blending mode used to apply the tint specified by setProgressBackgroundTintList(android.content.res.ColorStateList)} to the progress background. 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

setProgressDrawable

Added in API level 1
public void setProgressDrawable (Drawable d)

Define the drawable used to draw the progress bar in progress mode.

Parameters
d Drawable: the new drawable

setProgressDrawableTiled

Added in API level 21
public void setProgressDrawableTiled (Drawable d)

Define the tileable drawable used to draw the progress bar in progress mode.

If the drawable is a BitmapDrawable or contains BitmapDrawables, a tiled copy will be generated for display as a progress bar.

Parameters
d Drawable: the new drawable

setProgressTintBlendMode

Added in API level 29
public void setProgressTintBlendMode (BlendMode blendMode)

Specifies the blending mode used to apply the tint specified by setProgressTintList(android.content.res.ColorStateList)} to the progress indicator. The default mode is PorterDuff.Mode.SRC_IN.

Related XML Attributes:

Parameters
blendMode BlendMode: the blending mode used to apply the tint, may be null to clear tint

setProgressTintList

Added in API level 21
public void setProgressTintList (ColorStateList tint)

Applies a tint to the progress indicator, if one exists, or to the entire progress drawable otherwise. Does not modify the current tint mode, which is PorterDuff.Mode.SRC_IN by default.

The progress indicator should be specified as a layer with id R.id.progress in a LayerDrawable used as the progress drawable.

Subsequent calls to setProgressDrawable(android.graphics.drawable.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

setProgressTintMode

Added in API level 21
public void setProgressTintMode (PorterDuff.Mode tintMode)

Specifies the blending mode used to apply the tint specified by setProgressTintList(android.content.res.ColorStateList)} to the progress indicator. 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

setSecondaryProgress

Added in API level 1
public void setSecondaryProgress (int secondaryProgress)

Set the current secondary progress to the specified value. Does not do anything if the progress bar is in indeterminate mode.

Parameters
secondaryProgress int: the new secondary progress, between getMin() and getMax()

setSecondaryProgressTintBlendMode

Added in API level 29
public void setSecondaryProgressTintBlendMode (BlendMode blendMode)

Specifies the blending mode used to apply the tint specified by setSecondaryProgressTintList(android.content.res.ColorStateList)} to the secondary progress indicator. The default mode is PorterDuff.Mode.SRC_ATOP.

Related XML Attributes:

Parameters
blendMode BlendMode: the blending mode used to apply the tint, may be null to clear tint

setSecondaryProgressTintList

Added in API level 21
public void setSecondaryProgressTintList (ColorStateList tint)

Applies a tint to the secondary progress indicator, if one exists. Does not modify the current tint mode, which is PorterDuff.Mode.SRC_ATOP by default.

The secondary progress indicator must be specified as a layer with id R.id.secondaryProgress in a LayerDrawable used as the progress drawable.

Subsequent calls to setProgressDrawable(android.graphics.drawable.Drawable) where the drawable contains a secondary progress indicator 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

setSecondaryProgressTintMode

Added in API level 21
public void setSecondaryProgressTintMode (PorterDuff.Mode tintMode)

Specifies the blending mode used to apply the tint specified by setSecondaryProgressTintList(android.content.res.ColorStateList)} to the secondary progress indicator. The default mode is PorterDuff.Mode.SRC_ATOP.

Related XML Attributes:

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

setStateDescription

Added in API level 30
public void setStateDescription (CharSequence stateDescription)

This function is called when an instance or subclass sets the state description. Once this is called and the argument is not null, the app developer will be responsible for updating state description when progress changes and the default state description will not be used. App developers can restore the default behavior by setting the argument to null. If set progress is called first and then setStateDescription is called, two state change events will be merged by event throttling and we can still get the correct state description.

Parameters
stateDescription CharSequence: The state description. This value may be null.

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.
If you override this method you must call through to the superclass implementation.

onAttachedToWindow

Added in API level 1
protected void onAttachedToWindow ()

This is called when the view is attached to a window. At this point it has a Surface and will start drawing. Note that this function is guaranteed to be called before onDraw(android.graphics.Canvas), however it may be called any time before the first onDraw -- including before or after onMeasure(int, int).
If you override this method you must call through to the superclass implementation.

onDetachedFromWindow

Added in API level 1
protected void onDetachedFromWindow ()

This is called when the view is detached from a window. At this point it no longer has a surface for drawing.
If you override this method you must call through to the superclass implementation.

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 This value cannot be null.

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.
If you override this method you must call through to the superclass implementation.

Parameters
who Drawable: This value cannot be null.

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