Marshmallow 中的通知图标变为白色
Notification icon turns white in Marshmallow
我正在尝试使用具有透明背景的彩色图像作为通知图标。这在旧的 android 版本中工作正常,但当我在 Marshmallow(6.0) 上测试它时,它变成白色。我试图在 google 上找到解决方案并进行了尝试但没有成功。这是我的代码:
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);
}
请帮我解决这个问题。
根据 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.
您可以使用 setColor() 更改通知上可见的背景颜色,但小图标将始终只有 alpha-only,即由系统着色为单一颜色。
勾选这个,上面的Lollipop通知图标只能是白色或者透明的
我正在尝试使用具有透明背景的彩色图像作为通知图标。这在旧的 android 版本中工作正常,但当我在 Marshmallow(6.0) 上测试它时,它变成白色。我试图在 google 上找到解决方案并进行了尝试但没有成功。这是我的代码:
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);
}
请帮我解决这个问题。
根据 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.
您可以使用 setColor() 更改通知上可见的背景颜色,但小图标将始终只有 alpha-only,即由系统着色为单一颜色。
勾选这个