Android ProgressBar Tutorial With Example


Hello Readers! In this post, we are going to learn about android progressbar widget. We will also go through different attributes of android progressbar that can be used to customise progressBar widget.


Tutorialwing Android ProgressBar Output Android Progressbar widget tutorial example

Tutorialwing Android ProgressBar Output

Getting Started

Android progressbar can be defined as below –

A progressBar is a view that represents progress of an operation.

ProgressBar can be used in two ways depending on the types of operation. If you know the duration of an operation, you should use determinate progressBar. Determinate progressBar works only for a limited period of time. Or, If you do not know the duration of an operation, you should use indeterminate progressBar. Indeterminate progressBar works until you stop it.

Attributes of Android ProgressBar Widget

Now, we will go through different attributes of progressbar widget that can be used to customise this widget.

Sr. XML Attributes Description
1 android:indeterminate Enables indeterminate mode of the progressbar
2 android:indeterminateDrawable Sets drawable of the progressbar for the indeterminate mode
3 android:indeterminateDuration Sets duration of the indeterminate animation
4 android:max Sets maximum value
5 android:min Sets minimum value
6 android:progress Defines default progress value (between 0 and max value)
7 android:progressDrawable Drawable used for the progress mode
8 android:secondaryProgress Defines secondary progress value (between 0 and max value)

Some of the popular attributes of ProgressBar inherited from View are –

Sr. XML Attributes Description
1 android:alpha Sets alpha of view
2 android:background Sets background drawable for the view.
3 android:clickable Specifies if this view is clickable or not.
4 android:elevation Specifies base z-depth of the view.
5 android:id Specifies id of the view. Id must be unique.
6 android:onClick Specifies action to perform when this view is clicked.
7 android:padding Specifies padding of the view.
8 android:visibility Specifies visibility of the view. For example, VISIBLE, INVISIBLE etc.

Example of Android ProgressBar Widget

At First, we will create android project. Then, we will use progressBar widget in this project.

1. Creating New Project

Follow the steps below to create new project. Please ignore the steps if you have already created a new project.

Step Description
1. Open Android Studio.
2. Go to File => New => New Project. Write application name as ProgressBar. Then, click next button.
3. Select minimum SDK you need. However, we have selected 17 as minimum SDK. Then, click next button
4. Then, select Empty Activity => click next => click finish.
5. If you have followed above process correctly, you will get a newly created project successfully. However, you can also visit post to create a new project to know steps in detail.

Now, we will modify xml and java file to use progressBar widget in android.

2. Modify values folder

Open res/values/strings.xml file. Then, add below code into it.

	<string name="app_name">ProgressBar</string>

3. Use ProgressBar Widget in xml file

Open res/layout/activity_main.xml file. Then, add below code into it.

<?xml version="1.0" encoding="utf-8"?>


		android:text="Hide Progressbar"/>


In activity_main.xml file, we have added progressbar and button widget in xml file. Now, we will access this widget in file. Then, we will show/hide progressbar widget on button click.

4. Access ProgressBar Widget in java file

Open src/main/java/com.tutorialwing.progressbar/ file. Then, add below code into it.

package com.tutorialwing.progressbar;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;

public class MainActivity extends AppCompatActivity {

	protected void onCreate(Bundle savedInstanceState) {

		final ProgressBar progressBar = findViewById(;
		if (progressBar != null) {
			final Button btn = findViewById(;
			if (btn != null) {
				btn.setOnClickListener(new View.OnClickListener() {
					public void onClick(View v) {
						int visibility = (progressBar.getVisibility() == View.GONE) ? View.VISIBLE : View.GONE;

						String btnText = (progressBar.getVisibility() == View.GONE) ? "SHOW PROGRESSBAR" : "HIDE PROGRESSBAR";

In, we have accessed progressbar and button widget defined in activity_main.xml file. Then, we have added click listener on button to show/hide progressbar.

Since AndroidManifest.xml file is very important in any android application, we will also go through code inside this file.


Code inside src/main/AndroidManifest.xml file is as below –

<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.tutorialwing.progressbar"

		<activity android:name=".MainActivity">
				<action android:name="android.intent.action.MAIN"/>

				<category android:name="android.intent.category.LAUNCHER"/>


When we run the application, we will get output as shown above.

That’s end of tutorial on Android ProgressBar Widget.