Android Nougat的通知中未显示图标 [英] Icon is not getting displayed in notification in Android nougat

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

问题描述

我对此进行了研究,发现不建议使用 addAction(int图标,CharSequence标题,PendingIntent意图),因此我使用了 addAction(通知.Action action)。在这两种情况下,都看不到图标。

I researched about this and found out that addAction (int icon, CharSequence title, PendingIntent intent) is deprecated, so I used addAction (Notification.Action action) . In both the cases, icon cant be seen.

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

notificationBuilder.addAction(action);

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

The text seems to be working though, but I have left it blank, hence there is an empty space below the main image, where icon is supposed to be displayed

推荐答案

这不是错误,而是设计上的更改Android牛轧糖。设备不再显示由 addAction(Notification.Action操作) 定义的图标。还是旧设备和Android Wear设备仍需要它们!

This is not an error, but a change in the design with Android Nougat. Icons defined by addAction (Notification.Action action) are not any more displayed by devices. They still are required for older devices and Android Wear devices!

引用 Android开发人员Google博客


您会注意到图标未出现在新通知中;
会在通知阴影的
受限空间中为标签本身提供更多空间。但是,通知
操作图标仍然是必需的,并且会继续在较旧的
版本的Android和Android Wear等设备上使用。

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.

如果您一直使用
NotificationCompat.Builder和
可用的标准样式来构建通知,则默认情况下您将获得新的外观,而无需更改代码

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.

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

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