首页 文章

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

提问于
浏览
0

我试图使用透明背景的彩色图像作为通知图标 . 这适用于较旧的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);
}

请帮我摆脱这个问题 .

2 回答

  • 1

    根据Android 5.0 behavior changes

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

    您可以使用setColor()更改通知上可见的背景颜色,但小图标将始终仅为alpha-only,即由系统着色为单色 .

  • 0

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

相关问题