Android notification icon color does not change when background color is white

I updated android 6.0 and my application was having problems.

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

but if some applications change the background color to white, my notification icon is not inverted to black.

How can I invert the white notification icon to black when the background color in the status bar is set to white by another application? (I am not saying how I can use the color icon.)

The image below shows the problem.

normal status

when the background color changes to white, my icon does not change to black only

  • 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> 

** Solution found **

I added notification icons to drawable directory not drawable- * dpi. Now it works.

+5
source share
2 answers

I know it's too late to answer, but for others who have the same problem,

I had this problem too, and I found that the problem is related to the graphic icon. You can solve the problem using this online tool. open this link:

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

then select an image (with a large dimension), then upload the resource and copy it to your project.

then set the notification icon with .setSmallIcon(R.drawable.ICON_NEW_NAME)

hope this help

+2
source

I think the problem is with the Android 5.0 device or higher.

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

Here is the 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 getNotificationIcon() method:

 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; } 
0
source

All Articles