接受的答案并不(完全)正确。当然,它使通知图标以颜色显示,但这样做有一个很大的缺点 - 将目标 SDK 设置为低于 Android Lollipop!
如果您按照建议将目标 SDK 设置为 20 来解决白色图标问题,您的应用将不会针对 Android Lollipop,这意味着您无法使用 Lollipop 特定的功能。
看一下http://developer.android.com/design/style/iconography.html,您会看到白色样式是 Android Lollipop 中通知的显示方式。
在 Lollipop 中,Google 还建议您使用显示在(白色)通知图标后面的颜色 -https://developer.android.com/about/versions/android-5.0-changes.html
因此,我认为更好的解决方案是向应用程序添加一个剪影图标,并在设备运行 Android Lollipop 时使用它。
例如:
Notification notification = new Notification.Builder(context)
.setAutoCancel(true)
.setContentTitle("My notification")
.setContentText("Look, white in Lollipop, else color!")
.setSmallIcon(getNotificationIcon())
.build();
return notification;
并且,在 getNotificationIcon 方法中:
private int getNotificationIcon() {
boolean useWhiteIcon = (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP);
return useWhiteIcon ? R.drawable.icon_silhouette : R.drawable.ic_launcher;
}