Android通知显示错误的图标 [英] Android notification displays wrong icon

查看:175
本文介绍了Android通知显示错误的图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有Icon ID的静态数组:

I have a static Array with Icon ids:

public static final int[][] ICON_IDS = { {R.drawable.ic_access_alarm_black_24dp, R.drawable.ic_access_time_black_24dp, R.drawable.ic_account_box_black_24dp, R.drawable.ic_add_black_24dp, R.drawable.ic_android_black_24dp, R.drawable.ic_clear_black_24dp, R.drawable.ic_delete_black_24dp },
        { R.drawable.ic_settings_black_24dp, R.drawable.ic_airplanemode_active_black_24dp, R.drawable.ic_filter_list_black_24dp, R.drawable.ic_account_box_black_24dp, R.drawable.ic_airline_seat_individual_suite_black_24dp, R.drawable.ic_delete_black_open_24dp, R.drawable.ic_delete_black_open_24dp}};

我显示所有图标,用户可以选择一个。所选图标的ID将传递给通知管理器。它显示如下通知:

I display all the icons and the user can choose one. The id of the chosen icon is passed to the notification manager. It displays the notification like this:

NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(this)
                    .setSmallIcon(notification.getIconId())
                    .setContentTitle(notification.getTitle());

我已经使用test-ImageView检查了ID是否正确。 ImageView显示用户选择的图标(使用 setImageResource(notification.getIconId());)。但是在通知栏中的通知上显示另一个图标或没有。
如果我使用.setLargeIcon(),它会再次显示正确的图标。

I have checked with an "test-ImageView" that the id is correct. The ImageView displays the icon the user selected (with setImageResource(notification.getIconId());). But on the notification in the notification bar another icon is displayed or none. If I use .setLargeIcon() it shows the correct icon again.

.setLargeIcon(BitmapFactory.decodeResource(getResources(), notification.getIconId()))

但仅限于大图标。小图标为空。

But only in the big icon. The small icon is empty.

图标是通过矢量资产导入的素材图标。

The icons are the material icons imported via vector assets.

有什么问题用这个?

推荐答案

找出原因。您不能将xml资源用作通知图标。

Found out why. You can't use xml resources as Notification Icons.

这篇关于Android通知显示错误的图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆