Akshay
Akshay

Reputation: 5765

Display indeterminate progressbar in Status bar on Android

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?

Upvotes: 5

Views: 4701

Answers (2)

Akshay
Akshay

Reputation: 5765

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);

Upvotes: 5

ernazm
ernazm

Reputation: 9258

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.

Upvotes: 1

Related Questions