简体   繁体   中英

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:

白色的铃铛图标

This is how it appears in the status bar:

带有白色图标的状态栏

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

带有白色图标的通知

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM