67

I have this code:

Notification notif;

// Build notification
Notification.Builder notifBuilder = new Notification.Builder(context);
notifBuilder.setContentIntent(pendingIntent);
notifBuilder.setContentTitle(title);
notifBuilder.setSmallIcon(icon_resId);
notifBuilder.setContentText(ne.getCaption());
notifBuilder.setDefaults(Notification.DEFAULT_ALL);
notifBuilder.setAutoCancel(autocancel);
notifBuilder.setWhen(System.currentTimeMillis());
notif = notifBuilder.build();

and works fine in Android 4.4.

However, in Android 5.0 the icon showed in status bar is a white square. The icon showed in the new "notification body", that appears when device is locked, is correct.

In http://developer.android.com/reference/android/app/Notification.Builder.html, I don't see anything new about notification icons in API Level 21

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
Borja
  • 1,091
  • 1
  • 9
  • 16

8 Answers8

33

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."

porlicus
  • 739
  • 1
  • 7
  • 14
  • 5
    The documentation has changed: https://www.google.com/design/spec/patterns/notifications.html "Be opaque white, using only the alpha channel." – Ben Oct 15 '15 at 18:19
  • 4
    Neither the link by porlicus or Ben currently say anything about the small icon specifications. – JoeMjr2 May 28 '17 at 22:49
  • An archived version is available [here](http://web.archive.org/web/20150209195038/http://developer.android.com/design/style/iconography.html#notification) – caw Mar 15 '21 at 03:56
32

I have resolved changing the icon size to 16x16 px and using only white color

Borja
  • 1,091
  • 1
  • 9
  • 16
  • 3
    You didn't noticed all notifications are masked white in lollipop? In order to use good icons in lollipop you should use an icon with a noticable shape. All colors will be translated to white so transparancy is a must. – Dion Segijn Dec 01 '14 at 12:12
  • Full asset size of the Image should be 72*72 within an optical square of 66 * 66 in order to show properly. Please refer to http://petrnohejl.github.io/Android-Cheatsheet-For-Graphic-Designers/ – SavageKing Mar 16 '15 at 10:05
  • @SavageKing that's a great resource but hasn't been updated for Lollipop. In particular, the notification icon sizes no longer scale correctly compared to Google apps. Best as I can tell, they're using an icon of 80x80 within an image of 96x96 for xxxhdpi. – Sterling Apr 19 '15 at 03:45
  • what do you mean using only white color? so you small icon is JUST a white square or what???? – Boris Gafurov Oct 04 '17 at 20:46
4

As noted in Android 5.0 Behavior Changes of the Android Developers site under Notifications:

Notifications are drawn with dark text atop white (or very light) backgrounds to match the new material design widgets. Make sure that all your notifications look right with the new color scheme. If your notifications look wrong, fix them:

Use setColor() to set an accent color in a circle behind your icon image. Update or remove assets that involve color. The system ignores all non-alpha channels in action icons and in the main notification icon. You should assume that these icons will be alpha-only. The system draws notification icons in white and action icons in dark gray.

http://developer.android.com/about/versions/android-5.0-changes.html.

bummi
  • 27,123
  • 14
  • 62
  • 101
CoDeSigns
  • 141
  • 1
  • 2
4

Duplicate : Notification bar icon turns white in Android 5 Lollipop

In a Brief :

Android 5 update : https://developer.android.com/about/versions/android-5.0-changes.html Notifications -> Material design style

Update or remove assets that involve color. The system ignores all non-alpha channels in action icons and in the main notification icon. You should assume that these icons will be alpha-only. The system draws notification icons in white and action icons in dark gray.

It's possible to set the small icon background color using (default is gray) :

Notification.Builder#setColor(int)
Community
  • 1
  • 1
Tobliug
  • 2,992
  • 30
  • 28
3

Add this in your manifest -

 <meta-data android:name="com.google.firebase.messaging.default_notification_icon"
    android:resource="@drawable/ic_notification" />
A J
  • 4,542
  • 5
  • 50
  • 80
2

Anyone still looking at this, the simplest way of getting your icon to display correctly is first rendering it with the Android Icon Studio here:

https://romannurik.github.io/AndroidAssetStudio/icons-notification.html

Unzip the files from the downloaded zip into your project /main folder, so they slot into the relevant drawable-xxxx folders.

Then, to change colour in the notification use something like this:

NotificationCompat.Builder builder = new NotificationCompat.Builder(context, CHANNEL_ID)
    .setSmallIcon(R.drawable.ic_notification_appicon) // <-- Icon from Android Icon Studio 
    .setColor(context.getColor(R.color.holo_blue))    // <-- Set your preferred icon colour to appear in the notification dropdown list
    .setContentTitle("Title")
    .setContentText("Content")
    .setAutoCancel(true)
    .setCategory(NotificationCompat.CATEGORY_EVENT)
    .setDefaults(Notification.DEFAULT_ALL)
    .setPriority(NotificationCompat.PRIORITY_DEFAULT);
0

In Android 5.0 the icon showed in the status bar is a white square because of 5.0 Lollipop "Notification icons must be entirely white".

You can easily find this types of icons on the Material icon. Visit: https://material.io/icons/

Google also suggests that we use a custom color that will be displayed behind the white notification icon using setColor() method.

For more information visit: https://developer.android.com/about/versions/android-5.0-changes.html

Aashish Kumar
  • 2,771
  • 3
  • 28
  • 43
-3

Remove the android:targetSdkVersion="21" from manifest.xml. it will work!

CopsOnRoad
  • 237,138
  • 77
  • 654
  • 440
范文锋
  • 157
  • 4
  • 76
    This is not a solution, it is a bad way of going against the system. – SagiLow Jan 24 '15 at 16:21
  • is there any solutions with android:targetSdkVersion="21" version in manifest file? – John May 15 '15 at 14:11
  • 3
    @john, no but setting android:targetSdkVersion="19" works great as well. To everyone else: I don't quite understand the dislike of this answer. The problem is basically "Lollipop doesn't want to do things the way I want to do them". Therefor logically your choices are accept the lollipop way, or don't target lollipop. – netsplit Jun 16 '15 at 17:41
  • 2
    Why was `targetSdkVersion` in manifest.xml in the first place? These things should be set in build.gradle. – IgorGanapolsky Oct 02 '15 at 14:53
  • this solution would not work. even stop the notification in sdk ver 21 or above. – Mohsin Feb 23 '16 at 08:03
  • Very lazy solution! It doesn't really solve anything. Its like asking us to ducktape a broken building pillar and consider it solved. You cannot suggest to downgrade a project's target SDK version as some stakeholders wanted to target latest android devices. For instance, an inbuilt app for an OEM. – Neon Warge Mar 06 '17 at 01:43