Reputation: 51
I'm setting an icon, by using a .png in white, transparent background. It's working ok when displaying in the lock screen, and in the notification area.
The icon is the highlighted in yellow: enter image description here
Now in the notification drawer the icon is shown in white too (is the same icon). enter image description here
But I would like to use another icon, in this case the truck in blue. Right now I'm setting the color to blue by using Notification.Builder.SetColor(), and the title appears in that color.
You can see how the Gmail icon displays in white in the status bar, and red in the drawer.
This is the actual code to build the notification. Code is for Xamarin.Droid
var notificationManager = GetSystemService(Context.NotificationService) as NotificationManager;
Notification.Builder builder = new Notification.Builder(this)
.SetContentTitle(title)
.SetContentText(desc)
.SetSmallIcon(Routes.Droid.Resource.Drawable.truck)
.SetAutoCancel(true);
builder.SetLargeIcon(BitmapFactory.DecodeResource(Resources, Resource.Drawable.truckColor));
builder.SetColor(Android.Graphics.Color.Rgb(33,150,243));
var notification = new Notification.BigTextStyle(builder).BigText(desc).Build();
notificationManager.Notify(-1, notification);
How can I set the icon color in the notification drawer, or use different icons?
The objective is to display the icon in white in the notification area, and in blue in the notification drawer.
Upvotes: 3
Views: 3987
Reputation: 51
The icon color is set automatically by Android 7.0 (API 24).
For the icon to be colored by Android, you have to use specific resources for the different densities, and add them in the corresponding directories.
In my app, I added the icons to
/Resources/drawable-hdpi
/Resources/drawable-xhdpi
/Resources/drawable-xxhdpi
If you, like in my case, have an image for the icon, you can create the new resources by using this tool: https://romannurik.github.io/AndroidAssetStudio/icons-notification.html
Source code doesn't change, but when setting the icons for the diferent densities, the icon get's colored in the drawer, and white in the notification area.
Previously I was just using a default .png icon in the Resources/drawable folder. This displays the icon, but it appears always in the same color.
Upvotes: 2