2012-07-08 138 views
0

我想爲我的通知設置另一個默認圖標。我使用parse.com的通知服務,並希望更改通知欄中的圖標。更改通知圖標

有沒有可能不改變標題和文字與Notification.Builder

+0

你是說你使用[推送解析通知](https://www.parse.com/docs/android_guide#push)或什麼?請編輯你的問題,並更具體的方式。 – 2012-07-08 21:31:38

+0

是的,我想爲我的通知使用其他圖標,這可能嗎? – Ahmad 2012-07-08 21:33:47

回答

1

發佈您的源代碼如何創建您的通知。

但通常,要更改通知圖標,只需調用setSmallIcon或setLargeIcon方法即可。這裏是一個例子:

Notification notif = new Notification.Builder() 
    .setContentTitle("New mail from " + sender.toString()) 
    .setContentText(subject) 
    .setSmallIcon(R.drawable.new_mail) 
    .setLargeIcon(aBitmap) 
    .build(); 

在你的情況,只是提供一個不同的圖標drawable給setSmallIcon方法。

+0

user1253575,你已經在你的[上一個問題](http://stackoverflow.com/questions/11379518/android-change-notification-icon)中詢問了這個問題,並在那裏得到了一個包含該信息的答案。如果你還不清楚,那就問問那裏。 – 2012-07-08 21:49:02

1

在比ICS

Notification notification = new Notification(R.drawable.logo, "", System.currentTimeMillis()); 
notification.largeIcon = your bitmap 
notification.icon = your drawable 
+0

我不知道爲什麼,但這是行不通的。有什麼你必須先設置?任何權限? – Ahmad 2012-07-08 22:23:35

+0

@Mr_and_Mrs_D嗯,我認爲它調用Notification類的其他構造函數後確實工作(不記得不過,自從我發佈這個問題已經有一年多的時間了)。然而,azgolfer發佈的答案實際上更好(現在 - 通過支持庫 - 可用於較低的Android版本)。我重新回答了這個問題。感謝您指出了這一點! :) – Ahmad 2013-07-19 13:56:08

1

的android下你必須要實現自定義接收器的解析推送通知爲described in Parse's documentation

這樣,解析是不會自動生成的Android用戶通知,然後你可以自己做,在較新的Android版本Notification.BuilderNotification()在較舊的Android版本,如在其他的答案中描述有提供自定義圖標。