How to show an indeterminate horizontal progress bar in android? The animation of the progress bar should start from 0 to 100 and then go back from 100 to 0 continuously. I am not looking for the wheel progress bar.
In Android, by default a progress bar will be displayed as a spinning wheel but If we want it to be displayed as a horizontal bar then we need to use style attribute as horizontal. It mainly use the “android. widget. ProgressBar” class.
By default, every progress bar (created using one of several JProgressBar constructors) is determinate. You may make any JProgressBar indeterminate using the setIndeterminate method: pb. setIndeterminate(true);
An indeterminate ProgressBar shows a cyclic animation without an indication of progress.
I already knew that setIndeterminate
will give an infinite horizontal progress bar. But it will be similar to the loading wheel, except that it will be horizontal. If you see my question I was looking for horizontal bar which starts from 0 and goes all the way to 100 (a gradual increase). If you want to achieve this in Android, you must use your progress bar as below:
<ProgressBar android:id="@+id/progress_horizontal" android:indeterminateOnly="false" android:indeterminateDrawable="@drawable/progress_indeterminate_horizontal" android:progressDrawable="@drawable/progress_horizontal" android:minHeight="24dip" android:maxHeight="24dip" android:layout_width="fill_parent" android:layout_height="wrap_content"/>
As I wanted to change the background of my progress bar, I changed the ProgressDrawable and IndeterminateDrawable. The original drawables are located under frameworks/base/core/res/res/drawable
. Copy them to your project and change the color according to your needs.
Create a thread which updates the progress count and does a Thread.Sleep
. Then it sends the message to the Handler which will update the progress bar in UI thread.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With