开发者

Display indeterminate progressbar in Status bar on Android

I am trying to display an animated graphic identical to the indeterminate progre开发者_开发问答ss 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜