I am trying to show a icon on the notification bar. The icon is a LevelListDrawable which could change the content by setting levels. The question is I can't set level to the icon in the notification. I have tried to use "Notification.icon" and "Notification.iconLevel" but it's not works.
Here is my code fragment. can anyone see what's wrong?
Notification notification = new Notification(R.drawable.ic_stat_notify, "", System.currentTimeMillis());
notification.icon = R.drawable.ic_stat_notify;
notification.iconLevel = 30;
notification.setLatestEventInfo(context, "Hello", "World", intent);
manager.notify(NOTIFICATION_ID, notification);
Here is my LevelListDrawable
?xml version="1.0" encoding="utf-8"?>
level-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="@drawable/ic_stat_notify_0"
android:minLevel="0"
android:maxLevel="9"/>
<item android:drawable="@drawable/ic_stat_notify_10"
android:minLevel="10"
android:maxLevel="11"/>
<item android:drawable="@drawable/ic_stat_notify_20"
android:minLevel="20"
android:maxLevel="29"/>
<item android:drawable="@drawable/ic_stat_notify_30"
android:minLevel="30"
android:maxLevel="39"/>
<item android:drawable="@drawable/ic_stat_notify_40"
android:minLevel="40"
android:maxLevel="49"/>
<item android:drawable="@drawable/ic_stat_notify_50"
android:minLevel="50"
android:maxLevel="59"/>
<item android:drawable="@drawable/ic_stat_notify_60"
android:minLevel="60"
android:maxLevel="69"/>
<item android:drawable="@drawable/ic_stat_notify_70"
android:minLevel="70"
android:maxLevel="79"/>
<item android:drawable="@drawable/ic_stat_notify_80"
android:minLevel="80"
android:maxLevel="89"/>
<item android:drawable="@drawable/ic_stat_notify_90"
android:minLevel="90"
android:maxLevel="99"/>
<item android:drawable="@drawable/ic_stat_notify_100"
android:minLevel="100"
android:maxLevel="100"/>
</level-list>
If you want to show a certain icon for the notification in the expanded notifications list, you should create the notification with a "normal" drawable without iconLevel and on first update you can set another icon (a level-list ex.) and set the iconLevel.
For updating the icon in the status bar
notification.icon = R.drawable.ic_stat_notify;
notification.iconLevel = 30;
manager.notify(NOTIFICATION_ID, notification);
it's important to call notify() to make updates visible, and won't update the icon in the expanded list, unless you recreate the notification.
This is a possible duplicate of this: android Notification setSmallIcon with level-list
It appears to be a bug in Android. When updating a notification with a level list, the status bar icon updates, but the icon in the notification pulldown does not. It has been reported here: http://code.google.com/p/android/issues/detail?id=43179&q=setSmallIcon&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.