Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing notification icon background on Lollipop

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

like image 343
Zsolt Boldizsár Avatar asked Dec 07 '14 13:12

Zsolt Boldizsár


People also ask

How do I change the background color on my notifications?

call setColor -> the color to be used on the background. call setColorized -> the actual call to set the background color. set style to NotificationCompat. DecoratedMediaCustomViewStyle()

How do I change the color of my notification icons on my Android?

Step 1: After opening the android studio and creating a new project with an empty activity. Step 2: Navigate to res/values/colors. xml, and add a color that you want to change for the status bar.

Can you change Colour of notifications on Android?

From the main settings menu, "Notification Theme" allows you to change the background color of your notifications. You can enable a dark theme, light theme, the system default, or choose from a selection of colors.


2 Answers

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)

like image 160
Eugen Pechanec Avatar answered Sep 19 '22 13:09

Eugen Pechanec


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.

like image 24
satyapol Avatar answered Sep 19 '22 13:09

satyapol