Android Color Notification Icon –
Development issue/problem:
I’m working on an application in which I make a notification for the user. I want the icon to appear in white when it is in the status bar, but in blue when it appears in the notification drop-down menu. Here is an example of the same with the Google Store application.
The message is white in the status bar:
Color message in the drop-down menu :
How can I do it again? Which properties do I need to repair?
Edit:
Here is my current code – I’ve made the image completely white with a transparent background, so it looks good in the status bar, but the image remains the same white color as the notifications:
private NotificationCompat.Builder getNotificationBuilder() {get a new NotificationCompat.Builder(mainActivity).setDeleteIntent(deletedPendingIntent).setContent(startChatPendingIntent).setAutoCancel(true).setSmallIcon(R.drawable.skylight_notification).setColor(ContextCompatible.getColor(mainActivity, R.color.colorPrimary)).setContentTitle(mainActivity.getString(R.string.notification_title)).setContentText(mainActivity.getString(R.string.notification_prompt));}.
How can I solve this problem?
Solution 1:
I found the answer to my question here: https://stackoverflow.com/a/44950197/4394594
I don’t know exactly what the problem was, but by putting the large png I used for the icon in this tool https://romannurik.github.io/AndroidAssetStudio/icons-notification.html#source.type=image&source.space.trim=1&source.space.pad=0&name=ic_skylight_notification
and placing the generated icons in my mipmap folder, I was able to make the setColor(…) property work correctly.
Solution 2:
For Firebase notifications sent from the console, simply add them to your :
Where white_logo is the white logo of your application and custom_color is the color you want to use to color the icon and text white.
More information can be found here: https://firebase.google.com/docs/cloud-messaging/android/client
Solution 3:
This is what I did for my app….
private void showNotification(Context) {
Log.d(MainActivity.APP_TAG, Displaying Notification);
Intent = new Intent(context, MainActivity.class);
PendingIntent = PendingIntent.getActivity(context, 0, activityIntent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context);
mBuilder.setSmallIcon(R.drawable.ic_notification);
mBuilder.setColor(Color.GREEN);
mBuilder.setContentIntent (pending deIntent);
mBuilder.setContentTitle (EarthQuakeAlert);
mBuilder.setContentText (long time no verification of seismic data!);
mBuilder.setDefaults (Notification.DEFAULT_SOUND);
mBuilder.setAutoCancel(true);
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(1, mBuilder.build());
}
Colour swatches :
Colourless patterns :
Solution 4:
You can set the color and icon when creating an alert. If your icon is a pure white image, it will be colored in the right places.
as (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
fall manager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
fall notificationId = 10 // A unique identifier.
// Channel creation – mandatory for notifications O.
fall channel = NotificationChannel (my_channel_01,
Channel human readable title,
NotificationManager.IMPORTANCE_DEFAULT).
manager.createNotificationChannel(channel)
// Build notification.fall builder = Notification.builder(context, channel.id)builder.setContentTitle(Warning!)builder.setContentText(This is a bad notification!)builder.setSmallIcon(R.drawable.skull)builder.setColor(ContextCompatible.getColor(context, R.color.colorPrimary))builder.setChannelId(channel.id)
// Send the notification.
manager.notify(notificationId, builder.build())
}
Solution No 5:
If you want to change the color and name of the header in a push notification or a built-in notification in order to adapt it to Gmail and Twitter, you need to add these lines to the notification.
builder.setSmallIcon(R.drawable.skull)
builder.setColor(ContextCompatible.getColor(context, R.colorPrimary))
The first line is used for the symbol and the second line should define the color
Solution No 6:
You can use DrawableCompat.setTint(int drawable); to draw before setting the drawable.
And make the mutation() drawable, otherwise a colour shadow will be applied to each copy of the drawing.
Solution No 7:
Create a notification icon using the Asset Studio available in Android Studio itself (right-click the res folder and select New > Picture Assets).
New Android Studio Image Menu
Then set the colour of the message
int color = Color.argb(255, 228, 14, 18) ;
NotificationCompat.Builder notificationBuilder =
new NotificationCompatible.Builder(this, channelId)
.setSmallIcon(R.drawable.ic_stat_notification)
.setContentTitle(title)
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent)
.setColor(color)
.setPriority(NotificationCompat.PRIORITY_HIGH)
Good luck!
Related Tags:
notification icon showing white android,notification color code,what is batch management in android,notificationcolorutil,how to make notification panel black,android notification setcolor not working,android notification icon generator,list of app notification icons,android notification icon is grey,react-native-firebase notification icon,notification icon not showing android oreo,android notification large icon not showing,notification android,android notification styles,push notification in android using firebase,how to turn on notifications on android phone,change notification light color android,change lock screen notification color,blur notification panel android,notification bar changer root,how to change notification bar color huawei,notification icon generator android,android notification small icon is grey,notification icon not showing android nougat,how to set push notification icon in android,push notification icon size,hms core,android app notification icons,android notification icon guidelines,change notification background color android,change notification text color android