ProgressBar

The ProgressBar view is a user interface element that indicates the progress of an operation.

Progress bar supports two modes to represent progress:

  • indeterminate - the default mode, which is used when you do not know how long the operation will take. In this mode view shows a cyclic animation without a specific amount of progress indicated.
  • determinate - mode, which is used 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.

By default, the accentColor is used for color of indicator.

indeterminate spinning wheel

By default, the ProgressBar is rendered as a spinning wheel in indeterminate mode. Or you can apply one of predefined style.

<ProgressBar
    android:id="@+id/progressBar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    ...
    />
    
    <ProgressBar
    android:id="@+id/progressBar1"
    style="?android:attr/progressBarStyleLarge"
    ...
    />

Predefined styles for the spinning wheel

  • progressBarStyleSmall - a small circular progress bar that can be placed in title bars
  • progressBarStyleLarge
  • progressBarStyleInverse
  • progressBarStyleSmallInverse
  • progressBarStyleLargeInverse

There are attributes to customize the spinning wheel:

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

You can use the RotateDrawable to show custom indicator with animation.

RotateDrawable example for progress bar

determinate progress bar

1. Add the progress bar to layout with the horizontal style

<!-- or style="?android:attr/progressBarStyleHorizontal" -->

<ProgressBar
    android:id="@+id/progressBar"
    style="@style/Widget.AppCompat.ProgressBar.Horizontal"  
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    ...
/>

2. Set the range of values (default [0; 100]) and change the current progress as needed in code.

progressBar.max = 120 // android:max attribute 
progressBar.min = 40 // android:min attribute 
progressBar.progress = 48 // android:progress attribute 

There are attributes to customize the progress bar:

  • android:max - defines the maximum value
  • android:min - defines the minimum value
  • android:progress - - defines the current progress
  • android:progressDrawable - drawable for the progress indicator
  • android:progressTint - tint to apply to the progress indicator
  • android:progressTintMode - blending mode used to apply the progress indicator tint
  • android:progressBackgroundTint - tint to apply to the progress indicator background
  • android:progressBackgroundTintMode - blending mode used to apply the progress indicator background tint

In addition, you can show the secondary progress of some subtasks.

  • 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

indeterminate progress bar

You can create it from the determinate progress bar by setting android:indeterminate attribute to true.

<ProgressBar
    android:id="@+id/progressBar"
             
    style="@style/Widget.AppCompat.ProgressBar.Horizontal"  
    android:max="100"
    android:progress="0"
    android:indeterminate="true"  
             
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    ...
/>

You can use the LevelListDrawable to show custom indicator with animation.

LevelListDrawable with gradient example for progress bar