I've been scouring stack overflow for days to find the answer to this question, but I cannot figure it out for the life of me :-/
On my Samsung S6 with Android O, apps like Gmail have white notifications for the status bar but red/blue/green/whatever notifications when you pull the notifications down to inspect them individually. See for example the attached photos - Gmail red when the notifications are displayed and white in the notification bar.
What type of programatic Android sorcery must one do to accomplish this? More specifically, in Notification.Builder, what values do I need to set to get it to display this way? Are there two different icons? Is there one drawable with multiple layers? If so, how does one choose which layers are shown where? Thanks!
From the main settings menu, "Notification Theme" allows you to change the background color of your notifications. You can enable a dark theme, light theme, the system default, or choose from a selection of colors.
Currently users can't change the notification icon, but I could make it possible to select one of the 300+ Automate icons. A custom picture isn't possible since Android requires the images to be packaged within the app.
First of all, we should be using NotificationCompat.Builder
Secondly, here is the code to get that behavior
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context, "NOTIFICATION_CHANNEL_NAME")
.setSmallIcon(R.drawable.notification_icon)
.setContentTitle(title)
.setContentText(message)
.setColor(ContextCompat.getColor(context, R.color.your_color))
.setContentIntent(pendingIntent);
There is one more thing, the icon that you are using (R.drawable.notification_icon
) should be white and should have a little bit of opacity (it should be just a little transparent). After that, your top notification icon will be white and when you draw notifications, it will become R.color.your_color
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With