Notification icon turns white in Marshmallow

蹲街弑〆低调 提交于 2019-12-30 14:45:15

问题


I am trying to use a colorful image with transparent background as notification icon. This works fine in older android versions but when i tested it on Marshmallow(6.0), it turns white. I tried to find the solution on google and tried them but no success. Here is my code:

NotificationManager notificationManager = (NotificationManager)
context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(icon, message, when);
String title = context.getString(R.string.app_name);
Intent notificationIntent = new Intent(context,Activity_Notification.class);
notificationIntent.putExtra("MSG", message);
if (notificationIntent != null){
int number = createRandomInteger();
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent intent;
intent = PendingIntent.getActivity(context, number,
notificationIntent, Intent.FLAG_ACTIVITY_CLEAR_TOP |
Intent.FLAG_ACTIVITY_NEW_TASK);
notification.setLatestEventInfo(context, title, message, intent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.defaults |= Notification.DEFAULT_SOUND;
notification.defaults |= Notification.DEFAULT_VIBRATE;
notificationManager.notify(number, notification);
}

Please help me to get rid of this problem.


回答1:


As per the Android 5.0 behavior changes:

The system ignores all non-alpha channels in action icons and in the main notification icon. You should assume that these icons will be alpha-only. The system draws notification icons in white and action icons in dark gray.

You can use setColor() to change the background color visible on the notification, but the small icon will always only be alpha-only i.e., colored a single color by the system.




回答2:


check this link, above Lollipop notification icon can only be white or transparent



来源:https://stackoverflow.com/questions/38067216/notification-icon-turns-white-in-marshmallow

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