2011-04-13 29 views
5

我試圖在我的進行中的通知處於活動狀態時,在狀態欄中顯示與不確定進度欄(不是水平的,而是圓形的)相同的動畫圖形。在Android上的狀態欄中顯示不確定的進度條

我試圖找到與不確定進度條對應的資源ID,但發現它是通過代碼動畫的。

我嘗試將我的Notification實例中的圖標ID設置爲動畫GIF,但狀態欄中只顯示GIF的第一幀。

如果我將圖標ID設置爲android.R.drawable.progress_indeterminate_horizo​​ntal,圖形完美動畫。所以,我的問題是 - 在這種情況下動畫是如何實現的?通過iconLevel?我如何設置一個動畫圖標,而不需要定期自己動畫?

任何指針將非常感激。

感謝,

阿克沙伊

回答

5

我找到了我的答案。要求是創建動畫列表(說保存爲my_spinner.xml)中,用由不同的角度旋轉的紡絲器的各種圖像從0到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> 

而且my_spinner.xml設置爲圖標ID時通知已創建。

Notification n = new Notification(R.drawable.my_spinner, null, 0); 
+0

此功能已被棄用,任何新的方式來做到這一點? – Rishabh876 2016-03-09 07:23:52

1

您可以通過請求適當的Windows功能和設置條可見顯示在標題中的進度條:

protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); 
    //any code here 
    setProgressBarIndeterminateVisibility(true); 

然而,它會出現在標題,不在狀態欄中。

+0

對不起,我知道標題中的進度條。我的要求是在狀態欄中顯示它。謝謝! – Akshay 2011-04-14 13:57:19