How to Embrace The Power of Android Progress Bar As a Usability Feature

android progress bar example

You might have noticed those bar filling itself when a task was in execution. Those bars are called progress bars. The Android progress bar is one of the common user interface components. It is used to show the progress of any task to the app users such as uploading, downloading, or to notify people that a task is running, how much task is left, or how much task has been finished.

In an Android progress bar tutorial, there are many ways to implement the Android progress bar feature, but here we’ll go through the simplest and most preferred way to show the progress of a running task.

Let’s Get Started

Create a new project under file menu and modify your project details.

Android progressbar demo

Choose Mini Support SDK in the next tab.

progressbar demo 2

Lastly, select Add No Activity and click on finish button.

android progressbar demo 3

Now we’ll create a XML layout file in which, we’ll add one progress bar and one button. When the user presses the button, it will show how much task is left and how much task is completed in the Android progress bar.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""
android:text="Download File" />

Now, we’ll create one class for MainActivity to define callback methods and represent a user interface within a single screen.

public class MainActivity extends AppCompatActivity {
ProgressDialog prgDialog;
private int prgStatus = 0;
private Handler prgBarHandler = new Handler();
private long fileSize = 0;
private Button btnStartPrg;
protected void onCreate(Bundle savedInstanceState) {
btnStartPrg = (Button) findViewById(;
btnStartPrg.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
// prepare for a progress bar dialog
prgDialog = new ProgressDialog(view.getContext());
prgDialog.setMessage("File downloading ...");
//reset progress bar status
prgStatus = 0;
//reset filesize
fileSize = 0;
new Thread(new Runnable() {
public void run() {
while (prgStatus < 100) {
// process some tasks
prgStatus = doSomeTasks();
// your computer is too fast, sleep 1 second
try {
} catch (InterruptedException e) {
// Update the progress bar Runnable() {
public void run() {
// ok, file is downloaded,
if (prgStatus >= 100) {
// sleep 2 seconds, so that you can see the 100%
try {
} catch (InterruptedException e) {
// close the progress bar dialog

Now that your user interface is ready and callback methods have been implemented, it’s time that we run the demo.

Android progressbar tutorial


Worked just fine, didn’t it?

However, this was just a simple example of progress bar in Android, but it’s also possible to use this feature for various jobs. And in case you need help to implement it, hire Android app developers, layout a strategic plan, and start execution.

Grab a free copy of android progress bar example from Github.

You may also like,

This page was last edited on April 28th, 2020, at 1:43.


Want to Develop Android App From Scratch? Contact Us Now

Get your free consultation now

Leave a Reply

Your email address will not be published. Required fields are marked *

Get Your Free Quote