Search code examples
androidapple-push-notificationsmaterial-designandroiddesignsupportandroid-notification-bar

How to support multiple colors (more than two color) for Android Notification icon?


  1. I am working on Android app (API level >23). And I have to support Notification.
  2. And my notification icon is supported more than two colors.
  3. If I use that icon then icon displays in grey in notification pannel.
  4. So I have created background transparent and completly white icon and set color dynamically.

  5. But I am able to set only one color (setColor()).

So my question is :-

How to support multiple colors (more than two color or color gradients) for Android Notification icon? Note :- I have taken reference of Android Push Notifications: Icon not displaying in notification, white square shown instead

Thanks for support in advance.


Solution

  • If your app targets SDK 21+ the system will always tint your notification icon

    • white when it's displayed in a dark status bar
    • dark grey when it's displayed on a light status bar (API 23+)
    • dark grey when it's collapsed at the bottom of the notification shade
    • the color you set when it's part of a notification in the notification shade (API 24+, before that you'd have a white icon over a colored circle as the default large notification icon)

    You have no control over the color other than what's described above.

    But you can work with alpha channel. You can achieve different degrees of white/dark grey/color in your icon.

    No, there's no other way. Pass this on to your designer and management.

    Android 5.0 Behavior Changes

    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.

    Source: https://developer.android.com/about/versions/android-5.0-changes.html#NotificationsMaterialDesignStyle