您的位置:首页 > 其它

解决5.0以上通知栏图标变白

2016-02-15 14:39 495 查看
5.0以上,系统会自动将通知栏图标全部填充为白色,解决方法如下:

final NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
//TODO
//FLAG_UPDATE_CURRENT:如果构建的PendingIntent已经存在,则替换它,常用
final PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
final Notification notification = new NotificationCompat.Builder(context)
.setContentTitle(title)
.setSmallIcon(R.drawable.ic_notification)
.setContentText(content)
.setDefaults(Notification.DEFAULT_ALL)//铃声、闪光、震动均系统默认。
.setContentIntent(pendingIntent)
.setAutoCancel(true)//设置这个标志当用户单击面板就可以让通知将自动取消
.build();

mNotificationManager.notify(notificationId, notification);


创建资源drawable和drawable-v21

1.drawable中放入和启动图标相同,名为ic_notification的图片

如:



2.drawable-v21中放入规矩形状的图片,命名为ic_notification

如:



简单来说就是把背景图层去掉

那么5.0以下会使用和启动图标相同的通知栏图标,5.0以上会使用简单的白色规矩图标,两种不同的图标
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: