Why notification color is different? - android

I am trying to set color to my notification action btns with next code:
.setColor(Color.parseColor("#ff7900"))
NotificationCompat.Builder(service, CHANEL_ID)
.setColor(Color.parseColor("#ff7900"))
.setContentIntent(piClick)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setSmallIcon(R.drawable.ic_notification)
.setShowWhen(false)
here is result:
but the real color is different - "#d14d00".
any ideas why it is happen and how it can be fixed?

you can try with this
builder.setColor(ContextCompat.getColor(context, R.color.yourColor));
or try with this
builder.setColor(context.getResources().getColor(R.color.yourColor));

Related

Whole Notification Background Color

I'm seeing some apps showing background color in whole notification.
Myntra Notification with BackgroundColor
First Cry Notification with BackgroundColor
I tried solutions from these links but nothing worked.
Changing Notification RemoteViews Background Color
https://cazimirroman.medium.com/android-how-to-set-the-background-color-for-a-notification-in-a-foreground-service-eaa505e2b82d
Tried using DecoratedMediaCustomViewStyle ->
val mediaSession = MediaSessionCompat(context,"tag")
mediaSession.setFlags(0)
mediaSession.setPlaybackState(PlaybackStateCompat.Builder()
.setState(PlaybackStateCompat.STATE_NONE,0,0f)
.build())
val builder = NotificationCompat.Builder(context, "channelId1")
.setSmallIcon(R.drawable.ic_notification_small)
.setContentTitle("The Title")
.setPriority(NotificationCompat.PRIORITY_MAX)
.setWhen(System.currentTimeMillis())
.setOngoing(true)
.setAutoCancel(true)
.setColor(ContextCompat.getColor(context, R.color.pink))
.setColorized(true)
.setStyle(androidx.media.app.NotificationCompat.DecoratedMediaCustomViewStyle().setMediaSession(mediaSession.sessionToken))
In this case notification is coming black always (suppose to be pink) and also doesn't show all the information.
Notification using MediaStyle
You should create two custom layouts for your notifications, one for a collapsed notification and one for an expanded notification, then in your activity:
RemoteView collapsedRV = new RemoteViews (getPackageName(), R.layout.collapsed_notification)
RemoteView expandedRV = new RemoteViews (getPackageName(), R.layout.expanded_notification)
then in your builder you need to set the content view like this:
.setCustomContentView(collapsedRV)
.setCutomBigContentView(expandedRV)
.build()
notificationManager.notify(1,builder)

How to change the background color of notification on Android 12

I would like to make the notification look a different color completely, I am using local notifications so I would like to be able to do this with NotificationCompat.Builder if possible.
Here's an example of what I would like the notification to look like:
Using notification builder methods
NotificationCompat.Builder(context, channelId)
.setColor(ContextCompat.getColor(this, R.color.primaryColor))
.setColorized(true)
.....
.build()

Displaying text in Android Status Bar

I am trying to display text in the Status Bar of Android Nougat just as time is displayed. I can display icons using NotificationCompat.Builder but not text. How to proceed?
If you're using NotificationCompat.Builder you can set text there
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.notification_icon)
.setContentTitle("My notification")
.setContentText("Hello World!")
You can also address this
Solved the problem by converting String to Bitmap. Got the idea from here

how to display proper small icon for notification is not getting displayed in Lollipop and Android M

I am creating an application, I am able to display notification properly, but small icon is not getting displayed as I have mentioned it in the drawable folder, The icon is getting masked with white color. Can any one help me, how can I get the icon to display properly.
Below is my notification code:
nb = new NotificationCompat.Builder(context)
.setContentTitle(contentTitle)
.setContentText(contentText)
.setSmallIcon(icon)
.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.micon_notification))
.setWhen(when)
.setContentIntent(contentIntent)
.setAutoCancel(true)
.setOnlyAlertOnce(true)
.setTicker(tickerText)
.setColor(Color.RED);
The icon mentioned in drawable is as shown below:
[1]: http://i.stack.imgur.com/ggYCY.png
That complete red color present inside the image is getting vanished and icon is getting displayed with complete white color. All suggestions are welcome.
This is the code Android uses to display notification icons:
if (entry.targetSdk >= Build.VERSION_CODES.LOLLIPOP) {
entry.icon.setColorFilter(mContext.getResources().getColor(android.R.color.white));
} else {
entry.icon.setColorFilter(null);
}
For that you've to make icon like Silhouette and make some section Transparent wherever you wants to add your Colors.
You can add your color using
.setColor(your_color_resource_here)
NOTE : setColor is only available in Lollipop so, you've to check OSVersion
if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
Notification notification = new Notification.Builder(context)
...
} else {
// Lollipop specific setColor method goes here.
Notification notification = new Notification.Builder(context)
...
notification.setColor(your_color)
...
}
Look at the documentation: http://developer.android.com/design/style/iconography.html
there are words:
"Notification icons must be entirely white. Also, the system may scale
down and/or darken the icons."
I hope it helps!

Android notifications different icon for status bar and notification body

I have a notification of battery level. I want to make different icon in status bar and notifications center. In status bar: number (2 digits). In body: my app icon.
How can I do that? The app icon is also in the status bar, how can I change that?
I'm not sure what your code looks like right now but I'd do something like this:
Notification.Builder nb = new Notification.Builder(context)
.setContentTitle("title")
.setContentText("content")
.setAutoCancel(true)
.setLargeIcon(R.drawable.large_icon)
.setSmallIcon(R.drawable.small_icon)
.setTicker("ticker text");
NotificationManager nm = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(100, nb.build());
Note the setLargeIcon() and setSmallIcon(). The icon you want to show in the 'ticker' should be set in setSmallIcon() and for what you have called the 'notification centre', you should use setLargeIcon(). That should work.

Categories

Resources