为什么在 Android Lollipop 中使用 Notification.Builder.setSmallIcon 设置的图标显示为白色方块? [英] Why do icons set with Notification.Builder.setSmallIcon in Android Lollipop show as a white square?

查看:14
本文介绍了为什么在 Android Lollipop 中使用 Notification.Builder.setSmallIcon 设置的图标显示为白色方块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个代码:

Notification notif;

// Build notification
Notification.Builder notifBuilder = new Notification.Builder(context);
notifBuilder.setContentIntent(pendingIntent);
notifBuilder.setContentTitle(title);
notifBuilder.setSmallIcon(icon_resId);
notifBuilder.setContentText(ne.getCaption());
notifBuilder.setDefaults(Notification.DEFAULT_ALL);
notifBuilder.setAutoCancel(autocancel);
notifBuilder.setWhen(System.currentTimeMillis());
notif = notifBuilder.build();

并且在 Android 4.4 中运行良好.

and works fine in Android 4.4.

但是,在 Android 5.0 中,状态栏中显示的图标是一个白色方块.设备锁定时出现的新通知正文"中显示的图标是正确的.

However, in Android 5.0 the icon showed in status bar is a white square. The icon showed in the new "notification body", that appears when device is locked, is correct.

http://developer.android.com/reference/android/app/Notification.Builder.html,我在 API 级别 21 中没有看到任何关于通知图标的新内容

In http://developer.android.com/reference/android/app/Notification.Builder.html, I don't see anything new about notification icons in API Level 21

推荐答案

我已解决将图标大小更改为 16x16 像素并仅使用白色

I have resolved changing the icon size to 16x16 px and using only white color

这篇关于为什么在 Android Lollipop 中使用 Notification.Builder.setSmallIcon 设置的图标显示为白色方块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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