19

I upgraded android 6.0 and my app have problem.

when the status bar background color is not white, notification icon is good. (notification icon png has white and alpha only)

but if some apps change background color to white, my notification icon isn't inverted to black.

How can I invert white notification icon to black when status bar background color set white by other app? (I'm not saying how can I use color icon.)

below image shows a problem.

normal status normal status image

when changed background color to white, my icon is not changed to black only with white background color image

  • Notification build code

      Notification.Builder mBuilder =
              new Notification.Builder(context)
                      .setSmallIcon(R.drawable.ic_notifications_none)
                      .setPriority(priority2)
                      .setOngoing(true);
    
      mBuilder.setContent(generateMessageView(message));
    
      Intent notificationIntent = new Intent(context, MainActivity.class);
      notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP 
                                | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    
      PendingIntent intent = PendingIntent.getActivity(context, 0,
              notificationIntent, 0);
      NotificationManager mNotificationManager =
              (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
      mBuilder.setContentIntent(intent);
      mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
    
  • values-v23/styles.xml

      <style name="AppTheme" parent="android:Theme.Material.NoActionBar">            
      </style>
    

Found a solution

I added notification icons to drawable directory not drawable-*dpi. Now it's working.

Omar Shawky
  • 1,242
  • 1
  • 12
  • 25
Jiyoung Kim
  • 191
  • 1
  • 1
  • 4
  • Check out this [post](http://stackoverflow.com/questions/28387602/notification-bar-icon-turns-white-in-android-5-lollipop). Also read this [documentation](http://developer.android.com/reference/android/app/Notification.Builder.html#setColor%28int%29). Hopefully you can get a clue. Cheers .... :) – Gypsy May 04 '16 at 03:51
  • @verbose I already read but will check again. thank you – Jiyoung Kim May 04 '16 at 05:12
  • I tried your solution and it didnt work for me. – Cerlin Jun 13 '17 at 11:31
  • I hope that you consider copying your solution from the question to an answer, it just solved my problem while non of this question's answers did but I saw what you wrote by pure luck. I could have just pass by, find no answer fitting, and then close your question though it already contains what I needed. – Omar Shawky Sep 14 '21 at 13:37

2 Answers2

19

It's late to answer, but for others who have the same problem,

I had this problem too and I found that the problem is with graphical icon. You can solve the problem by using this online tool. open this link:

https://romannurik.github.io/AndroidAssetStudio/icons-notification.html#source.type=image&source.space.trim=1&source.space.pad=0&name=ic_stat_call_white

choose your image ( with large dimension ), download the resource and copy them to your project.

and finally set the notification icon using .setSmallIcon(R.drawable.ICON_NEW_NAME)

hope this helps

Homayoon Ahmadi
  • 1,181
  • 1
  • 12
  • 24
1

I think the problem lies in device android 5.0 or high.

https://developer.android.com/design/patterns/notifications.html
https://developer.android.com/about/versions/android-5.0-changes.html

Here is a solution:

Notification notification = new Notification.Builder(context)
        .setAutoCancel(true)
        .setContentTitle("My notification")
        .setContentText("Look, white in Lollipop, else color!")
        .setSmallIcon(getNotificationIcon())
        .build();

return notification;

and method getNotificationIcon():

private int getNotificationIcon() {
    boolean useWhiteIcon = (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP);
    return useWhiteIcon ? R.drawable.icon_black : R.drawable.ic_nomarl;
}
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Nguyễn Trung Hiếu
  • 2,004
  • 1
  • 10
  • 22
  • thank you but It's not working. I found LNotifications from android sample and it hasn't black icon image but white to black(dark gray) when other app is running with white status bar. and I didn't found any special code kind of changing color from LNotifications. – Jiyoung Kim May 04 '16 at 04:38