Android Horizontal ProgressBar Tutorial With Example

We have recently published 100+ articles on android tutorials with kotlin and java. If you need, you may visit Android Tutorial for beginners page. You can also check Kotlin Tutorial for beginners. Also, if you are interested in content writing, you can mail us at

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


Tutorialwing Android Horizontal ProgressBar Output Android Horizontal Progressbar Widget tutorial with example

Tutorialwing Android Horizontal ProgressBar Output

Getting Started

Android ProgressBar widget can be defined as below –

Android progressBar widget is an user interface element that represents progress of an operation.

Horizontal progressBar has horizontal bar to show progress of an operation. You may have determinate / indeterminate mode for horizontal progressBar.

Attributes of Android horizontal progressbar Widget

We have already covered the attributes of android progressBar in ProgressBar Tutorial With Example tutorial. So, you may visit post to know more.

Example of Android Horizontal ProgressBar Widget

Now, we will create an android application. Then, we will use horizontal progressBar in this application.

1. Creating New Project

Follow the steps below to create new application. Pleas ignore the steps if you have already created an application.

Step Description
1. Open Android Studio.
2. Go to File => New => New Project. Write application name as ProgressBarHorizontal. 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 horizontal progressBar.

2. Modify Values folder

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

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

3. Use Horizontal 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 used progressbar and button widget. Now, we will access this widget in java file.
Note the style(“?android:attr/progressBarStyleHorizontal”) used in progressbar widget. This style is responsible for displaying progressbar in horizontal mode.

4. Access Horizontal ProgressBar Widget in java file

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

package com.tutorialwing.progressbarhorizontal;

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 file, we have accessed horizontal progressBar and button. Then, we have set click listener to show/hide progressbar when button is clicked.

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


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

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

		<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 the output as shown above.

That’s end of tutorial on Android Horizontal ProgressBar widget.

Support Us

If you like Tutorialwing and would like to contribute, you can email an article on any educational topic at We would love to publish your article. See your article on Tutorialwing and help others with your knowledge. Follow Facebook, LinkedIn, Google+, Twitter, Youtube for latest updates.
We have recently published 100+ articles on android tutorials with kotlin and java. If you need, you may visit Android Tutorial for beginners page. You can also check Kotlin Tutorial for beginners