android5.0 之后通知栏图标都修改了,小图标不能含有RGB图层,也就是说图片不能带颜色,只能用白色的图片,否则显示的就成白色方格了。如下图
但是我发现使用纯色的图片也是可以的,但是会底层会滤掉颜色变成白色内容。
知道问题就好修改了,5.0之后只能修改图标了。另一个办法就是将项目的targetSdkVersio改为21以下,就是5.0以下。新系统是兼容旧系统的,改为21以下,就能显示带有颜色的icon了。
下面说说通知消息的LargeIcon
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
Notification notification = builder
.setContentTitle("Title")
.setContentText("Content")
.setSmallIcon(R.mipmap.ic2)
.setLargeIcon(BitmapFactory.decodeResource(
getResources(), R.mipmap.ic_launcher))
.build();
manager.notify(1, notification);
smallIcon就是通知栏上面显示的小图标。
LargeIcon是下拉后显示的图标,看下图
那个机器人就是图片ic_launcher ,但是图片是没有包含右下角那个小图标的,右下角小图标是系统加的,小图标的图片就是smallIcon设置的icon。
可以看到小图标外面还有一圈灰色的外圈,这个颜色也是可以设置的,就是使用NotificationCompat.Builder 的serColor方法
Notification notification = builder
...
.setSmallIcon(R.mipmap.ic2)
.setColor(Color.parseColor("#ff0000"))
.setLargeIcon(BitmapFactory.decodeResource(
getResources(), R.mipmap.ic_launcher))
.build();
结果如下图外圈变红色了: