Most visited

Recently visited

Added in API level 1

ProgressBar

public class ProgressBar
extends View

java.lang.Object
   ↳ android.view.View
     ↳ android.widget.ProgressBar
Known Direct Subclasses
Known Indirect Subclasses


Visual indicator of progress in some operation. Displays a bar to the user representing how far the operation has progressed; the application can change the amount of progress (modifying the length of the bar) as it moves forward. There is also a secondary progress displayable on a progress bar which is useful for displaying intermediate progress, such as the buffer level during a streaming playback progress bar.

A progress bar can also be made indeterminate. In indeterminate mode, the progress bar shows a cyclic animation without an indication of progress. This mode is used by applications when the length of the task is unknown. The indeterminate progress bar can be either a spinning wheel or a horizontal bar.

The following code example shows how a progress bar can be used from a worker thread to update the user interface to notify the user of progress:

 public class MyActivity extends Activity {
     private static final int PROGRESS = 0x1;

     private ProgressBar mProgress;
     private int mProgressStatus = 0;

     private Handler mHandler = new Handler();

     protected void onCreate(Bundle icicle) {
         super.onCreate(icicle);

         setContentView(R.layout.progressbar_activity);

         mProgress = (ProgressBar) findViewById(R.id.progress_bar);

         // Start lengthy operation in a background thread
         new Thread(new Runnable() {
             public void run() {
                 while (mProgressStatus < 100) {
                     mProgressStatus = doWork();

                     // Update the progress bar
                     mHandler.post(new Runnable() {
                         public void run() {
                             mProgress.setProgress(mProgressStatus);
                         }
                     });
                 }
             }
         }).start();
     }
 }

To add a progress bar to a layout file, you can use the <ProgressBar> element. By default, the progress bar is a spinning wheel (an indeterminate indicator). To change to a horizontal progress bar, apply the Widget.ProgressBar.Horizontal style, like so:

 <ProgressBar
     style="@android:style/Widget.ProgressBar.Horizontal"
     ... />

If you will use the progress bar to show real progress, you must use the horizontal bar. You can then increment the progress with incrementProgressBy() or setProgress(). By default, the progress bar is full when it reaches 100. If necessary, you can adjust the maximum value (the value for a full bar) using the android:max attribute. Other attributes available are listed below.

Another common style to apply to the progress bar is Widget.ProgressBar.Small, which shows a smaller version of the spinning wheel—useful when waiting for content to load. For example, you can insert this kind of progress bar into your default layout for a view that will be populated by some content fetched from the Internet—the spinning wheel appears immediately and when your application receives the content, it replaces the progress bar with the loaded content. For example:

 <LinearLayout
     android:orientation="horizontal"
     ... >
     <ProgressBar
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         style="@android:style/Widget.ProgressBar.Small"
         android:layout_marginRight="5dp" />
     <TextView
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:text="@string/loading" />
 </LinearLayout>

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).

XML attributes

See ProgressBar Attributes, View Attributes

Summary

XML attributes

android:animationResolution Timeout between frames of animation in milliseconds

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

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  
android:max Defines the maximum value the progress can take. 
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: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

From class android.view.View

Inherited constants

From class android.view.View

Inherited fields

From class android.view.View

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

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

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

Get the progress bar's current level of progress.

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.

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.

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 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 ancestor 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 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(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 range of the progress bar to 0...

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 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(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 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(ColorStateList)} to the progress indicator.

void setSecondaryProgress(int secondaryProgress)

Set the current secondary progress to the specified value.

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(ColorStateList)} to the secondary progress indicator.

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

From class android.view.View
From class java.lang.Object
From interface android.graphics.drawable.Drawable.Callback
From interface android.view.KeyEvent.Callback
From interface android.view.accessibility.AccessibilityEventSource

XML attributes

android:animationResolution

Timeout between frames of animation in milliseconds

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

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol animationResolution.

android:indeterminate

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

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol indeterminate.

android:indeterminateBehavior

Defines how the indeterminate mode should behave when the progress reaches max.

Must be one of the following constant values.

ConstantValueDescription
repeat1 Progress starts over from 0.
cycle2 Progress keeps the current value and goes back to 0.

This corresponds to the global attribute resource symbol indeterminateBehavior.

android:indeterminateDrawable

Drawable used for the indeterminate mode.

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

This corresponds to the global attribute resource symbol indeterminateDrawable.

android:indeterminateDuration

Duration of the indeterminate animation.

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

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol indeterminateDuration.

android:indeterminateOnly

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

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol indeterminateOnly.

android:indeterminateTint

Tint to apply to the indeterminate progress indicator.

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

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol indeterminateTint.

Related methods:

android:indeterminateTintMode

Blending mode used to apply the indeterminate progress indicator tint.

Must be one of the following constant values.

ConstantValueDescription
src_over3 The tint is drawn on top of the drawable. [Sa + (1 - Sa)*Da, Rc = Sc + (1 - Sa)*Dc]
src_in5 The tint is masked by the alpha channel of the drawable. The drawable’s color channels are thrown out. [Sa * Da, Sc * Da]
src_atop9 The tint is drawn above the drawable, but with the drawable’s alpha channel masking the result. [Da, Sc * Da + (1 - Sa) * Dc]
multiply14 Multiplies the color and alpha channels of the drawable with those of the tint. [Sa * Da, Sc * Dc]
screen15 [Sa + Da - Sa * Da, Sc + Dc - Sc * Dc]
add16 Combines the tint and drawable color and alpha channels, clamping the result to valid color values. Saturate(S + D)

This corresponds to the global attribute resource symbol indeterminateTintMode.

Related methods:

android:interpolator

android:max

Defines the maximum value the progress can take.

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

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol max.

android:maxHeight

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

Must 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), mm (millimeters).

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol maxHeight.

android:maxWidth

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

Must 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), mm (millimeters).

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol maxWidth.

android:minHeight

android:minWidth

android:mirrorForRtl

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

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol mirrorForRtl.

android:progress

Defines the default progress value, between 0 and max.

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

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol progress.

android:progressBackgroundTint

Tint to apply to the progress indicator background.

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

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol progressBackgroundTint.

Related methods:

android:progressBackgroundTintMode

Blending mode used to apply the progress indicator background tint.

Must be one of the following constant values.

ConstantValueDescription
src_over3 The tint is drawn on top of the drawable. [Sa + (1 - Sa)*Da, Rc = Sc + (1 - Sa)*Dc]
src_in5 The tint is masked by the alpha channel of the drawable. The drawable’s color channels are thrown out. [Sa * Da, Sc * Da]
src_atop9 The tint is drawn above the drawable, but with the drawable’s alpha channel masking the result. [Da, Sc * Da + (1 - Sa) * Dc]
multiply14 Multiplies the color and alpha channels of the drawable with those of the tint. [Sa * Da, Sc * Dc]
screen15 [Sa + Da - Sa * Da, Sc + Dc - Sc * Dc]
add16 Combines the tint and drawable color and alpha channels, clamping the result to valid color values. Saturate(S + D)

This corresponds to the global attribute resource symbol progressBackgroundTintMode.

Related methods:

android:progressDrawable

Drawable used for the progress mode.

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

This corresponds to the global attribute resource symbol progressDrawable.

android:progressTint

Tint to apply to the progress indicator.

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

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol progressTint.

Related methods:

android:progressTintMode

Blending mode used to apply the progress indicator tint.

Must be one of the following constant values.

ConstantValueDescription
src_over3 The tint is drawn on top of the drawable. [Sa + (1 - Sa)*Da, Rc = Sc + (1 - Sa)*Dc]
src_in5 The tint is masked by the alpha channel of the drawable. The drawable’s color channels are thrown out. [Sa * Da, Sc * Da]
src_atop9 The tint is drawn above the drawable, but with the drawable’s alpha channel masking the result. [Da, Sc * Da + (1 - Sa) * Dc]
multiply14 Multiplies the color and alpha channels of the drawable with those of the tint. [Sa * Da, Sc * Dc]
screen15 [Sa + Da - Sa * Da, Sc + Dc - Sc * Dc]
add16 Combines the tint and drawable color and alpha channels, clamping the result to valid color values. Saturate(S + D)

This corresponds to the global attribute resource symbol progressTintMode.

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.

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

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol secondaryProgress.

android:secondaryProgressTint

Tint to apply to the secondary progress indicator.

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

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol secondaryProgressTint.

Related methods:

android:secondaryProgressTintMode

Blending mode used to apply the secondary progress indicator tint.

Must be one of the following constant values.

ConstantValueDescription
src_over3 The tint is drawn on top of the drawable. [Sa + (1 - Sa)*Da, Rc = Sc + (1 - Sa)*Dc]
src_in5 The tint is masked by the alpha channel of the drawable. The drawable’s color channels are thrown out. [Sa * Da, Sc * Da]
src_atop9 The tint is drawn above the drawable, but with the drawable’s alpha channel masking the result. [Da, Sc * Da + (1 - Sa) * Dc]
multiply14 Multiplies the color and alpha channels of the drawable with those of the tint. [Sa * Da, Sc * Dc]
screen15 [Sa + Da - Sa * Da, Sc + Dc - Sc * Dc]
add16 Combines the tint and drawable color and alpha channels, clamping the result to valid color values. Saturate(S + D)

This corresponds to the global attribute resource symbol secondaryProgressTintMode.

Related methods:

Public constructors

ProgressBar

Added in API level 1
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
ProgressBar (Context context, 
                AttributeSet attrs)

Parameters
context Context
attrs AttributeSet

ProgressBar

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

Parameters
context Context
attrs AttributeSet
defStyleAttr int

ProgressBar

Added in API level 21
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
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
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

getIndeterminateDrawable

Added in API level 1
Drawable getIndeterminateDrawable ()

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

Returns
Drawable a Drawable instance

See also:

getIndeterminateTintList

Added in API level 21
ColorStateList getIndeterminateTintList ()

Related XML Attributes:

Returns
ColorStateList the tint applied to the indeterminate drawable

See also:

getIndeterminateTintMode

Added in API level 21
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

See also:

getInterpolator

Added in API level 1
Interpolator getInterpolator ()

Gets the acceleration curve type for the indeterminate animation.

Returns
Interpolator the Interpolator associated to this animation

getMax

Added in API level 1
int getMax ()

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

Returns
int a positive integer

See also:

getProgress

Added in API level 1
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 0 and getMax()

See also:

getProgressBackgroundTintList

Added in API level 21
ColorStateList getProgressBackgroundTintList ()

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

Related XML Attributes:

Returns
ColorStateList the tint applied to the progress background

See also:

getProgressBackgroundTintMode

Added in API level 21
PorterDuff.Mode getProgressBackgroundTintMode ()

Related XML Attributes:

Returns
PorterDuff.Mode the blending mode used to apply the tint to the progress background

See also:

getProgressDrawable

Added in API level 1
Drawable getProgressDrawable ()

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

Returns
Drawable a Drawable instance

See also:

getProgressTintList

Added in API level 21
ColorStateList getProgressTintList ()

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

Related XML Attributes:

Returns
ColorStateList the tint applied to the progress drawable

See also:

getProgressTintMode

Added in API level 21
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

See also:

getSecondaryProgress

Added in API level 1
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 0 and getMax()

See also:

getSecondaryProgressTintList

Added in API level 21
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

See also:

getSecondaryProgressTintMode

Added in API level 21
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

See also:

incrementProgressBy

Added in API level 1
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
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

See also:

invalidateDrawable

Added in API level 1
void invalidateDrawable (Drawable dr)

Invalidates the specified Drawable.

Parameters
dr Drawable: the drawable to invalidate

isIndeterminate

Added in API level 1
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
void jumpDrawablesToCurrentState ()

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

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

onRestoreInstanceState

Added in API level 1
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.

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

onSaveInstanceState

Added in API level 1
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.

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

onVisibilityAggregated

Added in API level 24
void onVisibilityAggregated (boolean isVisible)

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

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

postInvalidate

Added in API level 1
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
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
void setIndeterminateDrawable (Drawable d)

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

Parameters
d Drawable: the new drawable

See also:

setIndeterminateDrawableTiled

Added in API level 21
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

See also:

setIndeterminateTintList

Added in API level 21
void setIndeterminateTintList (ColorStateList tint)

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

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

Related XML Attributes:

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

See also:

setIndeterminateTintMode

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

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

Related XML Attributes:

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

See also:

setInterpolator

Added in API level 1
void setInterpolator (Interpolator interpolator)

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

Parameters
interpolator Interpolator: The interpolator which defines the acceleration curve

setInterpolator

Added in API level 1
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.

Parameters
context Context: The application environment
resID int: The resource identifier of the interpolator to load

setMax

Added in API level 1
void setMax (int max)

Set the range of the progress bar to 0...max.

Parameters
max int: the upper range of this progress bar

See also:

setProgress

Added in API level 1
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 0 and getMax()

See also:

setProgress

Added in API level 24
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 0 and getMax()
animate boolean: true to animate between the current and target values or false to not animate

setProgressBackgroundTintList

Added in API level 21
void setProgressBackgroundTintList (ColorStateList tint)

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

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

Subsequent calls to setProgressDrawable(Drawable) where the drawable contains a progress background will automatically mutate the drawable and apply the specified tint and tint mode using setTintList(ColorStateList).

Related XML Attributes:

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

See also:

setProgressBackgroundTintMode

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

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

Related XML Attributes:

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

See also:

setProgressDrawable

Added in API level 1
void setProgressDrawable (Drawable d)

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

Parameters
d Drawable: the new drawable

See also:

setProgressDrawableTiled

Added in API level 21
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

See also:

setProgressTintList

Added in API level 21
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 SRC_IN by default.

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

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

Related XML Attributes:

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

See also:

setProgressTintMode

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

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

Related XML Attributes:

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

See also:

setSecondaryProgress

Added in API level 1
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 0 and getMax()

See also:

setSecondaryProgressTintList

Added in API level 21
void setSecondaryProgressTintList (ColorStateList tint)

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

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

Subsequent calls to setProgressDrawable(Drawable) where the drawable contains a secondary progress indicator will automatically mutate the drawable and apply the specified tint and tint mode using setTintList(ColorStateList).

Related XML Attributes:

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

See also:

setSecondaryProgressTintMode

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

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

Related XML Attributes:

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

See also:

Protected methods

drawableStateChanged

Added in API level 1
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.

onAttachedToWindow

Added in API level 1
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).

onDetachedFromWindow

Added in API level 1
void onDetachedFromWindow ()

This is called when the view is detached from a window. At this point it no longer has a surface for drawing.

onDraw

Added in API level 1
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
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
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
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.
Returns
boolean boolean If true than the Drawable is being displayed in the view; else false and it is not allowed to animate.

Hooray!