原因:对于 5.0 Lollipop,“通知图标必须是全白色的”。
如果我们通过将目标 SDK 设置为 20 来解决白色图标问题,我们的应用程序
不会针对 Android Lollipop,这意味着我们无法使用
Lollipop 特定的功能。
目标Sdk 21的解决方案
如果你想支持Lollipop Material Icons,那么就为Lollipop及以上版本制作透明图标。请参考以下内容:https://design.google.com/icons/ https://design.google.com/icons/
请看http://developer.android.com/design/style/iconography.html http://developer.android.com/design/style/iconography.html,我们将看到白色样式是通知在 Android Lollipop 中的显示方式。
在 Lollipop 中,Google 还建议我们使用显示在白色通知图标后面的颜色。参考链接:https://developer.android.com/about/versions/android-5.0-changes.html https://developer.android.com/about/versions/android-5.0-changes.html
无论我们想在哪里添加颜色https://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html#setColor(int) https://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html#setColor(int)
以下和以上 Lollipop 操作系统版本的通知生成器的实现如下:
Notification notification = new NotificationCompat.Builder(this);
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
notification.setSmallIcon(R.drawable.icon_transperent);
notification.setColor(getResources().getColor(R.color.notification_color));
} else {
notification.setSmallIcon(R.drawable.icon);
}
注意:setColor 仅在 Lollipop 中可用,并且仅影响图标的背景。
它将彻底解决你的问题!!