为什么在Android棒棒糖中用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中正常工作。

但是,在Android 5.0中,状态栏中显示的图标是白色方块。 设备locking时出现的新“通知主体”中显示的图标是正确的。

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

看看这个文档: http : //developer.android.com/design/style/iconography.html

有这样的话:“通知图标必须是完全白色的,而且,系统可能会缩小和/或使图标变暗。

我已经解决了将图标大小更改为16×16像素,只使用白色

重复: 通知栏图标在Android 5棒棒糖中变成白色

简介:

Android 5更新: https //developer.android.com/about/versions/android-5.0-changes.html通知 – >材质devise风格

更新或移除涉及颜色的资产。 系统忽略操作图标和主通知图标中的所有非alpha通道。 您应该假设这些图标将仅为阿尔法。 系统以白色和动作图标以深灰色绘制通知图标。

可以使用(默认为灰色)设置小图标背景颜色:

 Notification.Builder#setColor(int) 

正如在通知下Android开发者网站的Android 5.0行为变化中指出的那样:

通知在白色(或非常浅的)背景上用深色文本绘制,以匹配新的材料devise小部件。 确保所有的通知都使用新的配色scheme。 如果您的通知看起来不正确,请修正它们

使用setColor()在图标图像后面的圆圈中设置重音颜色。 更新或移除涉及颜色的资产。 系统忽略操作图标和主通知图标中的所有非alpha通道。 您应该假设这些图标将仅为阿尔法。 系统以白色和动作图标以深灰色绘制通知图标。

http://developer.android.com/about/versions/android-5.0-changes.html

从manifest.xml中删除android:targetSdkVersion =“21”。 它会工作!