Android notification has a color icon instead of being turned white
As suggested by Will Jones, the solution was to use a SVG file and convert it to XML using this: http://inloop.github.io/svg2android/. I then copied the file to android/app/src/main/res/drawable/notification_icon.xml
and deleted the old PNG file.
The icon now renders properly.
android notification icon showing as white block
I have found the solution!
I only found hints on what the requirements are for a Android Notification (SDK 22 / Version 5.1.1)but after searching for over 4 hours, finally a complete and working solution for this.
Here are the steps I followed and it seems to be inline with what is mentioned on various forums, questions/answers and doc, but no "steps/requirements" of what is needed:
Creating and preparing your image
- Create your image, however you want, take your app icon if you like:
Quick and dirty - Download an application to set transparency - I used IrfanView, it works well
Here is my image in IrfanView - Open your image in IrfanView,
click File > Save As or press 's'
You should have a
Save Dialog
open (and a save options dialog, top right - if not, right at the bottom of the save dialog, select theSave options dialog
checkbox, and it should open)My settings (which were given by default) are:
- Compression level - 6
- Use main window color for transparency - Checked
- Binary Encoding
- (ICO): Use main window color for transparency - Checked
Check the following 2 boxes:
- Save Transparent Color - Checked (I tried with only this checked, it didn't work - someone can extend on why not)
- Save Transparentcy as Alpha Channel - Checked
- Save as PNG file.
Save Box with Save Options
In Android Studio:
Right-Click Drawable folder > Add image asset
(any resource folder should do)- Click on
Notification Icon
from the top drop-down list (default isLauncher Icon
) - Select
Image > Browse to image> click ok
You will notice your image is greyscale
this is normal since the Lollipop SDK (API 21 - Ver 5.0.1)
only allows this type of color scheme, in searching I came across the materials design page which mentioned something in this line (Someone can extend on why this is)
Below, you will notice your notification icon in different 'dpi resolutions', adding a image normally will show a white block, but adding transparency solves this.
I believe one can use this from a 'colorful' perspective, in this case, IrfanView has a default background of black, this creating a "inverted" image in respect to this color (assuming in IrfanView, one leaves the "Use main windows color for transparency - checked" ) you can create different and interesting images.
I really hope this helps!
SmallIcon Color Turn To White Automatically Why In Notification Android?
.setSmallIcon(android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP ? R.mipmap.ic_launcher : R.drawable.notification_icon_bw_xhdpi)
.setColor(ResourcesCompat.getColor(getResources(), R.color.primary, getTheme()))
Use color to distinguish your app from others. Notification icons should only be a white-on-transparent background image. (https://developer.android.com/design/patterns/notifications.html)
Before Android Lollipop you can use same mipmap
icon for all notification icon. But from Lollipop onwards you need to create new notification icon (Silhoette kind of icon).
Android notification icon is a white circle
It seems to be a problem of cache during compilation ... The first image I was using was bad (fully colored), so I think my compilator created somekind of cache on the filename.
I work on Windows and did this : uninstall the app from my phone, invalidate all cache from Android sudio => at re-compilation, the icon was OK.
Do drawer notification icons have to be white?
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
Notification icon turns white in Marshmallow
As per the Android 5.0 behavior changes:
The system ignores all non-alpha channels in action icons and in the main notification icon. You should assume that these icons will be alpha-only. The system draws notification icons in white and action icons in dark gray.
You can use setColor() to change the background color visible on the notification, but the small icon will always only be alpha-only i.e., colored a single color by the system.
Android notification icon colour sometimes white, sometimes colourful
Well, I think the problem was something different. My code for creation the notification is only called, when the app is open on screen. When I receive a notification and the app is closed, the notification is handled by the Android system automaticly.
I had to set the color in the notification, which is send to the FCM Server:
$data = [
'notification' => [
'title' => 'Warnung: Wohnzimmer',
'text' => 'Innen: 20,3°C Außen: 24,5°C, Tendenz: -0,2°C',
'color' => '#83c3ed',
'sound' => 'default'
],
'to' => '/topics/testNotification'
];
Now I get a lightblue background icon within the app and also when the app is closed.
Notification icon on Android shown as a white square
I think you generated the icons of wrong size.
I re-generated them using the android asset studio and seems to be working at my end.
You can download then using this link:
https://romannurik.github.io/AndroidAssetStudio/icons-notification.html#source.type=text&source.text.text=capenergy&source.space.trim=1&source.space.pad=0&name=ic_stat_capenergy
Related Topics
Android Refresh a Fragment List from Its Parent Activity
How to Make Primary Key as Autoincrement for Room Persistence Lib
Onclick() to Change Button Border Color Rather Changing Button Color
Remove Span Tag With Text from String
Unable to Add Window - Token Null Is Not Valid; Is Your Activity Running
How to Send a Firebase Notification to All Devices Via Curl
Possible Unhandled Promise Rejection (Id:0) Error: Network Error in React Native
Java.Io.Filenotfoundexception Open Failed Eacces (Permission Denied) on Device
How to Fix White Screen on App Start Up
Android No on Screen Keybord ( Only Voice )
Limitations on Opening Pdf File in Android
Android Studio - Textview Not Showing in Design View Layout
Android Textview Text Not Getting Wrapped
How to Hide Action Bar for Fragment
How to Disable Recyclerview Items from Clicking
How to Enable/Disable Log Levels in Android
Access Ro.Serialno from Native in Android 8
How to Make Image Fill Relativelayout Background Without Stretching