Android.Widget.ProgressBar Class

See Also: ProgressBar Members

Syntax

[Android.Runtime.Register("android/widget/ProgressBar", DoNotGenerateAcw=true)]
public class ProgressBar : Android.Views.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(int) 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