mandy2
mandy2

Reputation: 1

How to create a Circular Indeterminate ProgressBar which is visible for a few milliseconds in Android Kotlin?

I want a Circular Indeterminate ProgressBar to be visible for a few milliseconds.

I have created a function to display the progress bar:

fun showProg(){
    binding.progBar.visibility = View.VISIBLE
    binding.progBar.visibility = View.INVISIBLE
}

Upvotes: 0

Views: 122

Answers (1)

Marat Zangiev
Marat Zangiev

Reputation: 1402

I think show/hide ProgressBar with time delay is not a good user experience and probably place of error.

It would be better to change progressBar state by behaviour, not time delay (for example: when data is loading progressBar is visible and invisible when loading completes).

But for your purpose will work fine this:

fun showProg(delayInMillis: Long) {
    with(binding.progBar) {
        visibility = View.VISIBLE
        postDelayed(delayInMillis) {
            visibility = View.INVISIBLE
        }
    }
}

Upvotes: 1

Related Questions