通知的小图标在Oreo上不会以灰色绘制?

问题描述

对于Android 21+通知,小图标必须仅包含Alpha。否则,android将它们绘制为灰色。

在这里放置了两种设备的通知屏幕截图,一种是Oreo,另一种是Pie,所以都是21 +

Android Pie(小米Mi 6),可以将图标绘制为灰色

enter image description here

Android Oreo(三星galaxy A-2016),小图标未绘制为灰色。 这不是很奇怪吗?

enter image description here

通知代码

 Notification notification = new NotificationCompat
            .Builder(this,CHANNEL_ID)
            .setSmallIcon(R.mipmap.ic_launcher_bos_new)
            .setContentTitle(title)
            .setContentText(message)
            .setSubText(subtitle)
            .setAutoCancel(true)
            .setLights(ContextCompat.getColor(this,R.color.yellow),1000,1000)
            .setTicker(getString(R.string.app_name))
            .build();

为什么在所有21种以上的设备上这种行为都不相同?

解决方法

因为在某个时候Google意识到通知栏背景可以是任何颜色,所以这意味着他们不得不将这些图标限制为仅使用Alpha通道。这样,系统可以自动为图标重新着色,以获得最大的对比度。