Android nougat 中的通知中未显示图标

Icon is not getting displayed in notification in Android nougat

我对此进行了研究,发现 addAction (int icon, CharSequence title, PendingIntent intent) 已被弃用,所以我使用了 addAction (Notification.Action action) 。在这两种情况下,都看不到图标。

NotificationCompat.Action action = new NotificationCompat.Action.Builder(R.drawable.ic_share, "", pendingIntent).build();

notificationBuilder.addAction(action);

虽然文字似乎有效,但我将其留空,因此在主图像下方有一个空的 space,应该显示图标的地方

这不是错误,而是 Android 牛轧糖的设计变更。设备不再显示由 addAction (Notification.Action action) 定义的图标。旧设备和 Android 磨损设备仍然需要它们!

引用 android developers google blog

You’ll note that the icons are not present in the new notifications; instead more room is provided for the labels themselves in the constrained space of the notification shade. However, the notification action icons are still required and continue to be used on older versions of Android and on devices such as Android Wear.

If you’ve been building your notification with NotificationCompat.Builder and the standard styles available to you there, you’ll get the new look and feel by default with no code changes required.