3

通知バーにアイコンを表示しようとしています。アイコンは、レベルを設定することでコンテンツを変更できる LevelListDrawable です。問題は、通知のアイコンにレベルを設定できないことです。「Notification.icon」と「Notification.iconLevel」を使用しようとしましたが、機能しません。

これが私のコードフラグメントです。誰が何が悪いのか見ることができますか?

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

これが私の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>
4

2 に答える 2

1

展開された通知リストに通知の特定のアイコンを表示する場合は、iconLevel を指定せずに「通常の」ドローアブルを使用して通知を作成する必要があり、最初の更新時に別のアイコン (例: レベル リスト) を設定して、アイコンレベル。

ステータスバーのアイコン更新用

    notification.icon = R.drawable.ic_stat_notify;
    notification.iconLevel = 30;
    manager.notify(NOTIFICATION_ID, notification);

notify() を呼び出して更新を表示することが重要です。通知を再作成しない限り、展開されたリストのアイコンは更新されません。

于 2012-07-17T07:50:36.310 に答える
0

これは次の重複の可能性があります: android Notification setSmallIcon with level-list

Android のバグのようです。レベル リストで通知を更新すると、ステータス バーのアイコンは更新されますが、通知プルダウンのアイコンは更新されません。ここで報告されています: http://code.google.com/p/android/issues/detail?id=43179&q=setSmallIcon&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars

于 2013-02-26T07:28:56.430 に答える