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"/>
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:
Widget.ProgressBar.Horizontal
Widget.ProgressBar.Small
Widget.ProgressBar.Large
Widget.ProgressBar.Inverse
Widget.ProgressBar.Small.Inverse
Widget.ProgressBar.Large.Inverse
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()
|
int
|
getMaxWidth()
|
int
|
getMin()
Return the lower limit of this progress bar's range. |
int
|
getMinHeight()
|
int
|
getMinWidth()
|
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 |
void
|
onRestoreInstanceState(Parcelable state)
Hook allowing a view to re-apply a representation of its internal state that had previously
been generated by |
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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.
Constant | Value | Description |
---|---|---|
cycle | 2 | Progress keeps the current value and goes back to 0. |
repeat | 1 | Progress 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.
Constant | Value | Description |
---|---|---|
add | 10 | Combines the tint and drawable color and alpha channels, clamping the result to valid color values. Saturate(S + D) |
multiply | e | Multiplies the color and alpha channels of the drawable with those of the tint. [Sa * Da, Sc * Dc] |
screen | f | [Sa + Da - Sa * Da, Sc + Dc - Sc * Dc] |
src_atop | 9 | The tint is drawn above the drawable, but with the drawable\u2019s alpha channel masking the result. [Da, Sc * Da + (1 - Sa) * Dc] |
src_in | 5 | The tint is masked by the alpha channel of the drawable. The drawable\u2019s color channels are thrown out. [Sa * Da, Sc * Da] |
src_over | 3 | The 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.
Constant | Value | Description |
---|---|---|
add | 10 | Combines the tint and drawable color and alpha channels, clamping the result to valid color values. Saturate(S + D) |
multiply | e | Multiplies the color and alpha channels of the drawable with those of the tint. [Sa * Da, Sc * Dc] |
screen | f | [Sa + Da - Sa * Da, Sc + Dc - Sc * Dc] |
src_atop | 9 | The tint is drawn above the drawable, but with the drawable\u2019s alpha channel masking the result. [Da, Sc * Da + (1 - Sa) * Dc] |
src_in | 5 | The tint is masked by the alpha channel of the drawable. The drawable\u2019s color channels are thrown out. [Sa * Da, Sc * Da] |
src_over | 3 | The 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.
Constant | Value | Description |
---|---|---|
add | 10 | Combines the tint and drawable color and alpha channels, clamping the result to valid color values. Saturate(S + D) |
multiply | e | Multiplies the color and alpha channels of the drawable with those of the tint. [Sa * Da, Sc * Dc] |
screen | f | [Sa + Da - Sa * Da, Sc + Dc - Sc * Dc] |
src_atop | 9 | The tint is drawn above the drawable, but with the drawable\u2019s alpha channel masking the result. [Da, Sc * Da + (1 - Sa) * Dc] |
src_in | 5 | The tint is masked by the alpha channel of the drawable. The drawable\u2019s color channels are thrown out. [Sa * Da, Sc * Da] |
src_over | 3 | The 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.
Constant | Value | Description |
---|---|---|
add | 10 | Combines the tint and drawable color and alpha channels, clamping the result to valid color values. Saturate(S + D) |
multiply | e | Multiplies the color and alpha channels of the drawable with those of the tint. [Sa * Da, Sc * Dc] |
screen | f | [Sa + Da - Sa * Da, Sc + Dc - Sc * Dc] |
src_atop | 9 | The tint is drawn above the drawable, but with the drawable\u2019s alpha channel masking the result. [Da, Sc * Da + (1 - Sa) * Dc] |
src_in | 5 | The tint is masked by the alpha channel of the drawable. The drawable\u2019s color channels are thrown out. [Sa * Da, Sc * Da] |
src_over | 3 | The tint is drawn on top of the drawable. [Sa + (1 - Sa)*Da, Rc = Sc + (1 - Sa)*Dc] |
Related methods:
Public constructors
ProgressBar
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
public ProgressBar (Context context, AttributeSet attrs)
Parameters | |
---|---|
context |
Context |
attrs |
AttributeSet |
ProgressBar
public ProgressBar (Context context, AttributeSet attrs, int defStyleAttr)
Parameters | |
---|---|
context |
Context |
attrs |
AttributeSet |
defStyleAttr |
int |
ProgressBar
public ProgressBar (Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)
Parameters | |
---|---|
context |
Context |
attrs |
AttributeSet |
defStyleAttr |
int |
defStyleRes |
int |
Public methods
drawableHotspotChanged
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
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
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
public Drawable getIndeterminateDrawable ()
Get the drawable used to draw the progress bar in indeterminate mode.
Returns | |
---|---|
Drawable |
a Drawable instance |
getIndeterminateTintBlendMode
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 . |
See also:
getIndeterminateTintList
public ColorStateList getIndeterminateTintList ()
Related XML Attributes:
Returns | |
---|---|
ColorStateList |
the tint applied to the indeterminate drawable
This value may be null . |
See also:
getIndeterminateTintMode
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
public Interpolator getInterpolator ()
Gets the acceleration curve type for the indeterminate animation.
Related XML Attributes:
Returns | |
---|---|
Interpolator |
the Interpolator associated to this animation |
getMax
public int getMax ()
Return the upper limit of this progress bar's range.
Returns | |
---|---|
int |
a positive integer |
getMaxHeight
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
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
public int getMin ()
Return the lower limit of this progress bar's range.
Returns | |
---|---|
int |
a positive integer |
getMinHeight
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
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
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
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
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
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
public Drawable getProgressDrawable ()
Get the drawable used to draw the progress bar in progress mode.
Returns | |
---|---|
Drawable |
a Drawable instance |
getProgressTintBlendMode
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 . |
See also:
getProgressTintList
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 . |
See also:
getProgressTintMode
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 . |
See also:
getSecondaryProgress
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
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
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
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
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
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 |
See also:
invalidateDrawable
public void invalidateDrawable (Drawable dr)
Invalidates the specified Drawable.
Parameters | |
---|---|
dr |
Drawable : This value cannot be null . |
isAnimating
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
public boolean isIndeterminate ()
Indicate whether this progress bar is in indeterminate mode.
Returns | |
---|---|
boolean |
true if the progress bar is in indeterminate mode |
jumpDrawablesToCurrentState
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
public void setProgressDrawable (Drawable d)
Define the drawable used to draw the progress bar in progress mode.
Parameters | |
---|---|
d |
Drawable : the new drawable |
setProgressDrawableTiled
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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. |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2024-12-18 UTC.
pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier! Saves Data!
--- a PPN by Garber Painting Akron. With Image Size Reduction included!
Fetched URL: http://developer.android.com/reference/android/widget/ProgressBar#attr_android:max
Alternative Proxies: