Stylish Progress Bar In Android

Stylish Progress Bar In Android With Kotlin | Android Example

ProgressBar in Android is a view that shows the progress of a current running task. A ProgressBar can be indeterminate or determinate. It depends on the need of the user what type of ProgressBar to use. So in this tutorial we will see how to make a Stylish Progress Bar In Android With Kotlin.

We use Indeterminate ProgressBar when we do not know how much time a given task will take. In this case the ProgressBar wheel keeps rotating until the task completes. Whereas the determinate ProgressBar shows the amount of task that has completed. For the horizontal ProgressBar see android Indeterminate progress bar .

 

Stylish Progress Bar In Android With Kotlin :

1- So, open Android Studio and make a new Android Studio Project. Name this project “ProgressBar Android” .

2- After the project builds you will have two files. MainActivity.kt file and activity_main.xml file.

3- Come to activity_main.xml file and first of all change the default Constraint Layout to Relative Layout.

activity_main.xml

4- In your activity_main.xml file you need two things. A button to make the ProgressBar visible and invisible and then you need a ProgressBar as well.

5- Give an id to your ProgressBar. Set width and height to wrap_content. Also add style and visibility to your ProgressBar like this.

 

 

6- Design your Button now. Select width as match_parent and height must be wrap_content. Provide margins, text and other attributes like this.

 

 

7- Here we complete our activity_main.xml file code. Our final activity_main.xml file is like this.

 

 

MainActivity.kt

 

8- In MainActivity.kt file define two variables for ProgressBar and Button.

 

 

9- Give ids to both views in onCreate method.

 

 

10- Now in onCreate method we have to give Layout Parameters. So that we can align the ProgressBar in the center of the Activity. We will use LayoutParams for this purpose.

 

 

11- In our onCreate method we will set an onClickListener method on our Button and then his click will show the ProgressBar if its not visible. So if its already visible the click will hide the ProgressBar.

 

 

12- Our code is complete now. So, here is the final code for our MainActivity.kt class.

 

 

So that’s it. This is the most simplest way to style the ProgressBar. There are many attributes to change the look of the ProgressBar. Must see the Android Developer page for further information. Have Fun 🙂

 

OUTPUT

 

Stylish Progress Bar In Android
Stylish Progress Bar In Android

 

Stylish Progress Bar In Android

 

 

 

   People Also Read:

 

Leave a Comment

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