1

My app is for API 26 or higher.

I am having an issue with the small icon in the notification. I went to the documentation here, and regardless of my issue, I saw that it is mentioned the icon has to be white, but as I am working right now I am listening to podcasts using the google podcast app and the icon is colorful. So does it have to be white or not? Or is it only google apps that can have colors?

enter image description here

link to the documentation: https://developer.android.com/guide/practices/ui_guidelines/icon_design_status_bar.html

My issue is that while my icon appears on top when the drawer is closed (it is the green icon by the colorful google podcast icon). But when the drawe is open, the icon doesn't show and it's just a blank greenish circle.

enter image description here

This is how I build the the notification:

                            Uri notificationSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
                            NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(something, ADMIN_CHANNEL_ID)
                                    .setSmallIcon(R.drawable.logo_fallback)
                                    .setLargeIcon(resource)
                                    .setContentTitle(remoteMessage.getData().get("title"))
                                    .setContentText(remoteMessage.getData().get("message"))
                                    .setAutoCancel(true)
                                    .setSound(notificationSoundUri)
                                    .setContentIntent(pendingIntent);

                            //Set notification color to match your app color template
                            notificationBuilder.setColor(getResources().getColor(R.color.colorPrimaryDark));
                            notificationManager.notify(notificationID, notificationBuilder.build());

and the resource I am using is a PNG. I've tried an XML too with no success.

E_net4
  • 27,810
  • 13
  • 101
  • 139
Tsabary
  • 3,119
  • 2
  • 24
  • 66

1 Answers1

0

Yes, icon should be white, You have to create an icon with white and transparent feature and set the deserved background color

NotificationCompat.Builder b = new NotificationCompat.Builder(ctx,Const.NOTIFICATION_CHANNEL);

            b.setAutoCancel(true)

                    .setDefaults(Notification.DEFAULT_ALL)
                    .setWhen(System.currentTimeMillis())
                    .setBadgeIconType(R.drawable.logo)
                    .setLargeIcon(BitmapFactory.decodeResource(ctx.getResources(),R.drawable.logo))
                    .setContentTitle(title)
                    .setContentText(message)
                    .setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_SOUND)
                    .setContentIntent(contentIntent);
            if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                b.setSmallIcon(R.drawable.new_logo);
                b.setColor(ctx.getResources().getColor(R.color.green));

            } else {
                b.setSmallIcon(R.drawable.logo);
            }

Here logo is coloured icon and new_logo is white icon

Athira
  • 1,177
  • 3
  • 13
  • 35
  • Thank you Athira, but I am still a bit confused about the icons. If I look at the example image I've placed for instance, you can see that the messenger icon is indeed white. I can do that by simply changing the icon in the setSmallIcon. But, when the notification drawer is expended, the Facebook messenger small icon is now full color blue (I'm talking about the icon on the top left corner - where I currently have just a dark green circle). Where is THAT logo declared? – Tsabary May 10 '19 at 09:17
  • make the area you want to set color as transparent and give color in setColor() – Athira May 10 '19 at 09:44
  • Edit your icon, replace coloured area with transparent, and set color in notification builder, it will look like color icon – Athira May 10 '19 at 09:48
  • Thank you. I t seems as if android doesn't except all colors. When I set it to a certain green, the icon is green but different. Same goes if I try a certain red for example. It's like android sets it to the closest color out of a list of allowed colors. Is there a list somewhere I can choose from? – Tsabary May 11 '19 at 00:20