Why do icons set with Notification.Builder.setSmallIcon in Android Lollipop show as a white square?

69,854

Solution 1

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

Solution 2

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

Solution 3

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.

Solution 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)

Solution 5

Add this in your manifest -

 <meta-data android:name="com.google.firebase.messaging.default_notification_icon"
    android:resource="@drawable/ic_notification" />
Share:
69,854
Borja
Author by

Borja

Updated on April 25, 2020

Comments

  • Borja
    Borja almost 4 years

    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

  • Dion Segijn
    Dion Segijn over 9 years
    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.
  • SagiLow
    SagiLow about 9 years
    This is not a solution, it is a bad way of going against the system.
  • SavageKing
    SavageKing about 9 years
    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 petrnohejl.github.io/Android-Cheatsheet-For-Graphic-Designer‌​s
  • Sterling
    Sterling about 9 years
    @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.
  • John
    John almost 9 years
    is there any solutions with android:targetSdkVersion="21" version in manifest file?
  • netsplit
    netsplit almost 9 years
    @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.
  • IgorGanapolsky
    IgorGanapolsky over 8 years
    Why was targetSdkVersion in manifest.xml in the first place? These things should be set in build.gradle.
  • Ben
    Ben over 8 years
    The documentation has changed: google.com/design/spec/patterns/notifications.html "Be opaque white, using only the alpha channel."
  • Mohsin
    Mohsin about 8 years
    this solution would not work. even stop the notification in sdk ver 21 or above.
  • Neon Warge
    Neon Warge about 7 years
    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.
  • JoeMjr2
    JoeMjr2 almost 7 years
    Neither the link by porlicus or Ben currently say anything about the small icon specifications.
  • Boris Gafurov
    Boris Gafurov over 6 years
    what do you mean using only white color? so you small icon is JUST a white square or what????
  • caw
    caw about 3 years
    An archived version is available here