Android Guides | Samples

Android.Widget.ProgressBar Class

See Also: ProgressBar

Syntax

[Android.Runtime.Register("android/widget/ProgressBar", DoNotGenerateAcw=true)]
public class ProgressBar : View

Remarks

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:

java Example

 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 NoType:android/R$style;Href=../../../reference/android/R.style.html#Widget_ProgressBar_Horizontal style, like so:

xml Example

 <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 ProgressBar.IncrementProgressBy(Int32) or ProgressBar.Progress. 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 NoType:android/R$styleable;Href=../../../reference/android/R.styleable.html#ProgressBar_max attribute. Other attributes available are listed below.

Another common style to apply to the progress bar is NoType:android/R$style;Href=../../../reference/android/R.style.html#Widget_ProgressBar_Small, which shows a smaller version of the spinning wheel&mdash;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&mdash;the spinning wheel appears immediately and when your application receives the content, it replaces the progress bar with the loaded content. For example:

xml 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 NoType:android/R$styleable;Href=../../../reference/android/R.styleable.html#ProgressBar, NoType:android/R$styleable;Href=../../../reference/android/R.styleable.html#View

[Android Documentation]

Requirements

Namespace: Android.Widget
Assembly: Mono.Android (in Mono.Android.dll)
Assembly Versions: 0.0.0.0
Since: Added in API level 1

The members of Android.Widget.ProgressBar are listed below.

See Also: View

Public Constructors

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

Protected Constructors

A constructor used when creating managed representations of JNI objects; called by the runtime.

Public Properties

IndeterminateBoolean.
IndeterminateDrawableDrawable.
IndeterminateTintListColorStateList.
IndeterminateTintModePorterDuff+Mode. Returns the blending mode used to apply the tint to the indeterminate drawable, if specified.
InterpolatorIInterpolator. Gets the acceleration curve type for the indeterminate animation.
MaxInt32.
ProgressInt32.
ProgressBackgroundTintListColorStateList. Returns the tint applied to the progress background, if specified.
ProgressBackgroundTintModePorterDuff+Mode.
ProgressDrawableDrawable.
ProgressTintListColorStateList. Returns the tint applied to the progress drawable, if specified.
ProgressTintModePorterDuff+Mode. Returns the blending mode used to apply the tint to the progress drawable, if specified.
SecondaryProgressInt32.
SecondaryProgressTintListColorStateList. Returns the tint applied to the secondary progress drawable, if specified.
SecondaryProgressTintModePorterDuff+Mode. Returns the blending mode used to apply the tint to the secondary progress drawable, if specified.

Protected Properties

[read-only]
override
ThresholdClassIntPtr. This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.
[read-only]
override
ThresholdTypeType. This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

Public Methods

IncrementProgressBy(Int32)
IncrementSecondaryProgressBy(Int32)
OnRestoreInstanceState(IParcelable)
Hook allowing a view to re-apply a representation of its internal state that had previously been generated by View.OnSaveInstanceState.
OnSaveInstanceState() : IParcelable
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.
SetIndeterminateDrawableTiled(Drawable)
Define the tileable drawable used to draw the progress bar in indeterminate mode.
SetInterpolator(Context, Int32)
Sets the acceleration curve for the indeterminate animation.
SetProgressDrawableTiled(Drawable)
Define the tileable drawable used to draw the progress bar in progress mode.