Kyle Kyle - 8 months ago 41
Android Question

How to get color of notification for Android?

Some notifications have their small notification icon appear as a badge in the bottom left corner of the big icon (See first, second and last notification).

enter image description here

However, post-Lollipop, the OS automatically sets a white color filter to the small icons and whenever I try to obtain them for display from my

, they're returned in white. Is there any way I can extract the background color for the small icons, or obtain the small icon directly as colored drawables, as-is? Below is my code, which only returns completely white icons.

public void onNotificationPosted(StatusBarNotification 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


The color can be retrieved from a notification via the color public field:

Notification notification = sbn.getNotification();
// ARGB color set with the notification
int color = notification.color;

There is also COLOR_DEFAULT as the default color of a notification, which you can use to see if a custom color is set at all.