1

I am trying to change the text colour of the app name which shows up just right to the app icon in Android notifications. Is it possible to achieve it?

I have noticed that the apps like Gmail, Messenger and other system apps do this. Gmail app name shows red in colour and Messenger app name shows in blue colour.

I have tried using the method setColor() of NotificationCompat.Builder but it seems that it changes only the colour of the notifications.

Can anyone please suggest me how I can implement the notifications exactly similar to Gmail app with InboxStyle notification.

Thanks in advance.

Duncan C
  • 128,072
  • 22
  • 173
  • 272
  • This is not an iOS question, so I deleted that keyword. – Duncan C Dec 29 '16 at 18:50
  • 1
    Try using a `ForegroundColorSpan` (e.g., via `SpannableStringBuilder`) when preparing the value for `setContentTitle()`. – CommonsWare Dec 29 '16 at 18:52
  • Try using a custom view? http://stackoverflow.com/questions/16168553/create-custom-notification-android – BiGGZ Dec 29 '16 at 19:44
  • Hi @CommonsWare, I want to change the text colour of the app name which is in the top header of each notification. I am able to change the colour of my other texts in the notification. I have uploaded an image here [http://imgur.com/a/x5BvI](http://imgur.com/a/x5BvI) for your better understanding. This is a Gmail app notification in Android N. – Puneet Agarwal Dec 30 '16 at 00:20
  • Hi @BiGGZ, I want to create the Gmail-style notification, and if I implement a custom view notification, then do I need to write all the expand and collapse animation? – Puneet Agarwal Dec 30 '16 at 00:25
  • Did you find any solution ? – deniz baş Nov 16 '21 at 11:47

1 Answers1

1

try this:

val builder = NotificationCompat.Builder(context, YOUR_NOTIFY_CHANNEL)
...
builder.setColor(ContextCompat.getColor(context, R.color.colorAccent))
...

val nm = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
nm.notify(YOUR_NOTIFY_TAG, YOUR_NOTIFY_ID, builder.build())
ZhouX
  • 1,866
  • 18
  • 22