Icon is not getting displayed in notification in Android nougat

蹲街弑〆低调 提交于 2020-01-10 02:29:42

问题


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


回答1:


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!

Quoting 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.



来源:https://stackoverflow.com/questions/41503972/icon-is-not-getting-displayed-in-notification-in-android-nougat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!