繁体   English   中英

棉花糖中的通知图标变为白色

[英]Notification icon turns white in Marshmallow

我正在尝试使用具有透明背景的彩色图像作为通知图标。 这在较旧的android版本中工作正常,但是当我在棉花糖(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的行为更改

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

您可以使用setColor()更改在通知中可见的背景颜色,但是小图标将始终仅是纯alpha样式的,即由系统上色。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM