Android Horizontal ProgressBar Using Kotlin 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

Hello Readers! In this post, we are going to learn how to use horizontal progressBar using kotlin in any android application. We will also learn how to add horizontal progressBar in linearLayout programmatically in any android application.


Tutorialwing Android Horizontal ProgressBar  Output Android horizontal progressbar in kotlin

Tutorialwing Android Horizontal ProgressBar Output

Getting Started

Android Horizontal progressBar can be defined as below –

Android ProgressBar is an user interface that represents progress of an operation. Here, Horizontal ProgressBar means progressBar as a horizontal line.

Different Attributes of Android Horizontal ProgressBar Widget

We have already covered attributes of horizontal progressBar in ProgressBar Widget Tutorial. Please this post to know more about different attributes.

Example of Android Horizontal ProgressBar Using Kotlin

1. Creating New Project in Kotlin

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

Step Description
1. Open Android Studio.
2. Go to File => New => New Project. Write application name as ProgressBarHorizontal. Then, check Include Kotlin Support and 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. You will get a newly created project successfully if you have followed steps properly.

Now, we will modify xml and other file to use horizontal progressBar using kotlin in the application.

2. Modify values folder

No values folders have been modified. So, we are not going to mention them here.

3. Use Horizontal ProgressBar Widget in xml file

Open src/main/res/layout/activity_main.xml file and add below code into it.

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


		android:text="Hide Progressbar"/>


In acitivity_main.xml file, we have defined a linearLayout and button. Button will be used to show/hide progressBar when it is clicked. Notice the styling style=”?android:attr/progressBarStyleHorizontal” in ProgressBar widget. This attribute is responsible for displaying progressBar horizontally.

4. Access Horizontal ProgressBar Widget using Kotlin file

Open src/main/java/com.tutorialwing.progressbarhorizontal/MainActivity.kt file and 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

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {

        val progressBar = findViewById<ProgressBar>(
        if (progressBar != null) {
            val btn = findViewById<Button>(
            btn?.setOnClickListener {
                val visibility = if (progressBar.visibility == View.GONE) View.VISIBLE else View.GONE
                progressBar.visibility = visibility

                val btnText = if (progressBar.visibility == View.GONE) "SHOW PROGRESSBAR" else "HIDE PROGRESSBAR"
                btn.text = btnText

Here, we have accessed button and horizontal progressBar using kotlin file (in MainActivity.kt). After that, we set a click listener on button to show / hide horizontal progressBar.

Since AndroidManifest.xml file is very important in any android application, we are also going to see the content inside this file.

AndroidManifest.xml file

Code inside 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 program, we will get output as shown above.

That’s end of our tutorial on Android Horizontal ProgressBaar using Kotlin.

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