Changing notification icon background on Lollipop

AndroidAndroid NotificationsAndroid 5.0-Lollipop

Android Problem Overview


I was going through the Notifications design pattern, and didn't find anything that talks about notification icon background. As you probably noticed, there is only a light grey background for custom notifications. But apps like Hangouts, or simply the USB Debugging notification has a custom color for their notification icon background.

Is there any possibility to change that grey into something else? (that specific circle's color programmatically)

See picture

Android Solutions


Solution 1 - Android

###1) Obtain Color

int color = 0xff123456;
int color = getResources().getColor(R.color.my_notif_color);
int color = ContextCompat.getColor(context, R.color.my_notif_color);

###2) Set the Color to the Notification

NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
...
builder.setColor(color);
Notification notif = builder.build();

The color is respected only on Lollipop and only affects background of the small icon. If a large icon is shown its contents are entirely your responsibility.

Source: NotificationCompat.Builder#setColor(int)

Solution 2 - Android

if you've defined color in colors.xml then in your NotificationBuilder add value as

.setColor(getResources().getColor(R.color.<YOUR_COLOR>))

That should solve your problem. It only affect to background of the icon.

Solution 3 - Android

getColor(int) has been deprecated on Resources

We should now use one of these alternatives:

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionZsolt Boldizs&#225;rView Question on Stackoverflow
Solution 1 - AndroidEugen PechanecView Answer on Stackoverflow
Solution 2 - AndroidsatyapolView Answer on Stackoverflow
Solution 3 - AndroidLuís RamalhoView Answer on Stackoverflow