VOOZH about

URL: https://www.geeksforgeeks.org/kotlin/dynamic-progressbar-in-kotlin/

⇱ Dynamic ProgressBar in Kotlin - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Dynamic ProgressBar in Kotlin

Last Updated : 12 Jul, 2025

Android ProgressBar is user interface control that is used to show some kind of progress. For instance, loading of some page, downloading of some file or waiting for some event to complete. In this article we will be discussing how to programmatically create a progress bar in Kotlin.

Step by Step Implementation

Step 1: Create a new project

To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio.

Step 2: Add ProgressBar Widget in activity_main.xml file

Navigate to app > res > layout > activity_main.xml and add a Progress bar and Button to show and hide the progress bar.

activity_main.xml:

Design UI:

👁 dynamic-progress-bar-design-ui


Step 3: Create ProgressBar in MainActivity.kt file

Navigate to app > src > main > java > {package-name} > MainActivity.kt.

In this file, we will declare a variable progressBar to create the ProgressBar widget

val progressBar = ProgressBar(this)
progressBar.layoutParams = LinearLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT
)

then add the widget in layout

val layout: LinearLayout = findViewById(R.id.layout)
layout.addView(progressBar)

MainActivity.kt:

Output:

Comment
Article Tags:

Explore