I am trying to display an animated graphic identical to the indeterminate progress bar (not the horizontal one, but the circular one) in the status bar while my on-going notification is alive.
I tried to find the resource ID corresponding to the indeterminate progress bar, but found that it is animated via code.
I tried setting the icon ID in my Notification instance to an animated GIF, but only the first frame of the GIF is displayed in the Status bar.
If I set the icon ID to android.R.drawable.progress_indeterminate_horizontal, the graphic animates perfectly. So, my question is- how is the animation achieved in this case? Through iconLevel? How can I set an animated icon without requiring to animate it periodically myself?
Indeterminate ProgressBars are a useful tool for communicating to our users that an operation is in progress when we cannot predict how long it is likely to take.
ProgressBar bar = new android. widget. ProgressBar(context); bar. setIndeterminate(true);
How do I stop indeterminate progress bar? An indeterminate progress bar animates constantly. You can stop the animation and clear the progress bar by making the progress bar determinate and setting the current value to the minimum.
To display a determinate progress bar, add the bar to your notification by calling setProgress(max, progress, false) and then issue the notification. The third argument is a boolean that indicates whether the progress bar is indeterminate (true) or determinate (false).
I found my answer. The requirement is to create an animation list (say saved as my_spinner.xml), with various images of the spinner rotated by different angles from 0 to 360.
<?xml version="1.0" encoding="utf-8"?>
<animation-list
xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item android:drawable="@drawable/spinner_0"
android:duration="200" />
<item android:drawable="@drawable/spinner_60"
android:duration="200" />
<item android:drawable="@drawable/spinner_120"
android:duration="200" />
<item android:drawable="@drawable/spinner_180"
android:duration="200" />
<item android:drawable="@drawable/spinner_240"
android:duration="200" />
<item android:drawable="@drawable/spinner_360"
android:duration="200" />
</animation-list>
And set my_spinner.xml as the icon ID when the notification is created.
Notification n = new Notification(R.drawable.my_spinner, null, 0);
You can display the progress bar in the title by requesting proper windows feature and setting bar visibility:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
//any code here
setProgressBarIndeterminateVisibility(true);
However, it will appear in the title, not in status bar.
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