某些通知的小通知图标在大图标的左下角显示为徽章(请参阅第一个,第二个和最后一个通知)。
然而,在Lollipop之后,操作系统会自动为小图标设置白色滤镜,每当我尝试从我的NotificationListenerService
获取它们时,它们都会以白色返回。有没有什么方法可以提取小图标的背景颜色,或直接获得小图标作为彩色drawables,原样?下面是我的代码,它只返回完全白色的图标。
public void onNotificationPosted(StatusBarNotification sbn) {
super.onNotificationPosted(sbn);
Bundle extras = sbn.getNotification().extras;
int smallNotiIcon = extras.getInt(Notification.EXTRA_SMALL_ICON);
//Code to display obtained small icon in an imageView shows up as white
}
答案 0 :(得分:1)
可以通过color公共字段从通知中检索颜色:
Notification notification = sbn.getNotification();
// ARGB color set with the notification
int color = notification.color;
还有COLOR_DEFAULT作为通知的默认颜色,您可以使用它来查看是否设置了自定义颜色。