Search code examples
c#androidxamarin.androidandroid-notifications

Android - Notification icon color not affected by setColor


I'm showing a notification in my app. I would like the small icon to be white in the status bar but another color (greenish) in the notification itself, as described in this question.

I'm using a 72x72, pure white, transparent, RGB-gamma-color-space PNG file as the icon:

white bell icon

This is how it appears in the status bar:

status bar with white icon

But it's still white in the notification itself (even though the app title gets the correct color):

notification with white icon

This is the code I use to display the notification:

using AndroidX.Core.App;

var builder = new NotificationCompat.Builder(this, "MY_CHANNEL")
    .SetSmallIcon(Resource.Mipmap.ic_notification_alert)
    .SetContentTitle("Test1")
    .SetContentText("This is a test")
    .SetColor(GetColor(Resource.Color.colorPrimary));

NotificationManagerCompat.From(this).Notify(777, builder.Build());

I already tried moving the icon to the drawable folder, the mipmap folder and using the tool mentioned in the aforementioned question. I'm testing on a Samsung Galaxy S7 with Android 8.0.0 installed. What am I missing?


Solution

  • Downscaling the icon to exactly 48x48 pixels suddenly made the correct color appear. I still don't understand this undocumented behavior.