【问题标题】:Notification icon turns white in MarshmallowMarshmallow 中的通知图标变为白色
【发布时间】:2016-06-28 04:45:00
【问题描述】:

我正在尝试使用具有透明背景的彩色图像作为通知图标。这在较旧的 android 版本中运行良好,但是当我在 Marshmallow(6.0) 上对其进行测试时,它变成了白色。我试图在谷歌上找到解决方案并尝试过但没有成功。这是我的代码:

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 android-notifications


【解决方案1】:

勾选这个link,上面的棒棒糖通知图标只能是白色或透明的

【讨论】:

    【解决方案2】:

    根据Android 5.0 behavior changes

    系统会忽略操作图标和主通知图标中的所有非 Alpha 通道。您应该假设这些图标仅是 Alpha 版。系统以白色绘制通知图标,以深灰色绘制操作图标。

    您可以使用setColor() 更改通知上可见的背景颜色,但小图标将始终只有 alpha 版本,即由系统着色为单一颜色。

    【讨论】: