Android ProgressBar

Android progressbar can be defined as below –

"A progressBar is a view that represents progress of an operation. For example, if you upload or download anything from the internet, it's better to show the user the progress of downloading/uploading."

We can use ProgressBar 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 don't know the duration of an operation, you should use indeterminate ProgressBar. Indeterminate progressBar works until you stop it.





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

S. No. XML Attributes Description
1 android:id This is unique id of the progressbar to uniquely identify the progressbar.
2 android:elevation Specifies base z-depth of the view.
3 android:clickable Specifies if this view is clickable or not.
4 android:background Sets background drawable for the view.
5 android:onClick Specifies action to perform when this view is clicked.
6 android:padding Specifies padding of the view.
7 android:visibility Specifies visibility of the view. For example, VISIBLE, INVISIBLE etc.
8 android:alpha Sets alpha of view.
9 android:indeterminate Enables indeterminate mode of the progressbar.
10 android:indeterminateDrawable Sets drawable of the progressbar for the indeterminate mode.
11 android:indeterminateDuration Sets duration of the indeterminate animation.
12 android:max Sets maximum value.
13 android:min Sets minimum value.
14 android:progress Defines default progress value (between 0 and max value).
15 android:progressDrawable Drawable used for the progress mode.
16 android:secondaryProgress Defines secondary progress value (between 0 and max value).





At first, we will create android project. Then, we'll use progressBar widget in this project.

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

S. No. Steps
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 14 as minimum SDK. Then, click next button
4 Then, select Empty Activity => click next => click finish.
  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 in android.

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

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

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

<?xml version="1.0" encoding="utf-8"?>
 < xmlns:android=""
app:layout_constraintTop_toTopOf="parent" />

android:text="Hide progressbar"
app:layout_constraintTop_toTopOf="@id/progress_circular" />

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





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

package com.ukacademe.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 btnShow = findViewById(;
            if (btnShow != null) {
                btnShow.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 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 xmlns:android=""

android:supportsRtl="true" android:theme="@style/AppTheme">
<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 below.

UK Academe-ProgressBar-Output