1

I am creating an application, I am able to display notification properly, but small icon is not getting displayed as I have mentioned it in the drawable folder, The icon is getting masked with white color. Can any one help me, how can I get the icon to display properly.

Below is my notification code:

nb = new NotificationCompat.Builder(context) .setContentTitle(contentTitle) .setContentText(contentText) .setSmallIcon(icon) .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.micon_notification)) .setWhen(when) .setContentIntent(contentIntent) .setAutoCancel(true) .setOnlyAlertOnce(true) .setTicker(tickerText) .setColor(Color.RED); 

The icon mentioned in drawable is as shown below:

[1]: https://i.sstatic.net/ggYCY.png 

That complete red color present inside the image is getting vanished and icon is getting displayed with complete white color. All suggestions are welcome.

1 Answer 1

2

This is the code Android uses to display notification icons:

if (entry.targetSdk >= Build.VERSION_CODES.LOLLIPOP) { entry.icon.setColorFilter(mContext.getResources().getColor(android.R.color.white)); } else { entry.icon.setColorFilter(null); } 

For that you've to make icon like Silhouette and make some section Transparent wherever you wants to add your Colors.

Iconography

You can add your color using

.setColor(your_color_resource_here) 

NOTE : setColor is only available in Lollipop so, you've to check OSVersion

if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { Notification notification = new Notification.Builder(context) ... } else { // Lollipop specific setColor method goes here. Notification notification = new Notification.Builder(context) ... notification.setColor(your_color) ... } 

Look at the documentation: http://developer.android.com/design/style/iconography.html

there are words:

"Notification icons must be entirely white. Also, the system may scale down and/or darken the icons."

I hope it helps!

Sign up to request clarification or add additional context in comments.

6 Comments

I have used set color, its adding color to the background of icon, Not working with setcolor method.
In the icon.setColorFilter, what is entry??
yes setColor is for changing background color. you have to design different icon like shown in above image for lollipop. on pre-lollipop version you can use existing icon. you can also follow iconography link.
it's just android source code to explain you that android itself set filter to white color for lollipop that's why your existing icon appears white in lollipop
here is link: developer.android.com/about/versions/android-5.0-changes.html about android lollipop notifications changes
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.