Android Progress Bar - ProgressBar Tutorial With Example | W3school

A Progress Bar is used to measure the progress of an ongoing task. For an instance, you can see the upload or download of an element to the or from the Internet, respectively. That’s where a progress bar comes into existence.

Also Read: Android RadioGroup Control

Various Methods Provided by the ProgressDialog Class
The creation of a progress bar in Android is only possible with the help of the ProgressDialog class. For that, instantiate an object of the ProgressDialog class and then you are good to proceed ahead. In order to do this, follow the given syntax:

ProgressDialog progress = new ProgressDialog(this); 

Now, you can easily set the required properties for your dialog. It may range from setting a message to a specific style.

progress.setMessage(“Downloading Music 🙂 “);


There are a few important and most commonly used methods offered by the ProgressDialog class. We have listed them out in the table provided below.

S. No. Method Description
1 getMax() * This method retrieves or returns the max value of the Progress Dialog.
2 setMax(int max) * This method sets the max value for the Progress Dialog.
3 setProgress(int value) * When you are required to update the Progress Dialog with some particular values then this method is taken into consideration.
4 incrementProgressBy(int diff) * This method is used to increment the progress bar by the diff value passed to it.
5 setIndeterminate(boolean indeterminate) * The progress indicator can either be set as determinate or indeterminate by using this method.
* It accepts either true or false.
6 show(Context context, CharSequence title, CharSequence message) * This is a static method.
* This method is used to display the Progress Dialog.

The following example will help you to include a progress bar in your application. The display of the progress bar will only be possible once the user clicks on the Button provided on the screen. Here, you will get a step-to-step guide to develop an Android application with the provision of a progress bar.

Step 1: Create an Android application with the name myapplication. This is to be done on the Android Studio IDE. Store this app under the com.example.w3school.myapplication package.

Step 2: Now, update the given code in the file. To find this file, look into the src/ folder. In this file, you are adding progress code as to display the progress dialog on the screen. Main activity file also contains the fundamental lifecycle callback methods as its default content.

package com.example.w3school.myapplication;
import android.os.Bundle;
import android.view.View;
import android.widget.Button; 

public class MainActivity extends ActionBarActivity
   Button b1;
   private ProgressDialog progress;   
   protected void onCreate(Bundle savedInstanceState)
      b1 = (Button) findViewById(;


   public void download(View view)
      progress=new ProgressDialog(this);
      progress.setMessage(“Downloading Music”);
      final int totalProgressTime = 100;
      final Thread t = new Thread()
         public void run()
            int jumpTime = 0;            
            while(jumpTime < totalProgressTime)
                  jumpTime += 5;
               } catch (InterruptedException e)
                  // TODO Auto-generated catch block

Step 3: Another file which needs modification is activity_main.xml. Add the following XML code to this file. You can easily identify this file after following the res/layout/ directory. 

<RelativeLayout xmlns:android=””
   xmlns:tools=”” android:layout_width=”match_parent”
   android:layout_height=”match_parent” android:paddingLeft=”@dimen/activity_horizontal_margin”
   android:paddingBottom=”@dimen/activity_vertical_margin” tools:context=”.MainActivity”>   

      android:text=”Progress bar” />      

      android:textColor=”#ff16ff01″ />      

      android:layout_centerVertical=”true” />      

Step 4: Let the AndroidManifest.xml file remain as it is.

<?xml version=”1.0″ encoding=”utf-8″?>
<manifest xmlns:android=””
   package=”com.example.w3school.myapplication” >
      android:theme=”@style/AppTheme” >   


         android:label=”@string/app_name” >      
            <action android:name=”android.intent.action.MAIN” />
            <category android:name=”android.intent.category.LAUNCHER” />

Step 5: Now, run this app in the Android Studio. For that, you will be required to have an AVD (must have created during the environment setup). Open one of the activity files from your project and click on the Run button. Before the process starts, you will get the following dialog box, asking you to choose one of the available options.

Select your mobile device and you will be displayed with the final output on your device. Now, the screen is having a “DOWNLOAD” button to offer. Once the user clicks on it, he/she will be displayed with a progress bar labeled as “Downloading Music”.