levi.hrb
levi.hrb

Reputation: 51

Set notificationbar icon color

I'm using android studio and want to match everything with my project colors. How can I set the color of the icons in the notificationbar? Or if not possible hide only the icons, not the bar?

enter image description here

Thanks in advance

Upvotes: 0

Views: 258

Answers (1)

Aadesh Mishra
Aadesh Mishra

Reputation: 135

When building the notification, you can set the color and the icon. (If your icon is a pure white image, it'll apply the color for you in the correct spots.)

here is my code I have used recently

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val manager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
val notificationId = 10 // Some unique id.

// Creating a channel - required for O's notifications.
val channel = NotificationChannel("my_channel_01",
        "Channel human-readable title",
        NotificationManager.IMPORTANCE_DEFAULT)

manager.createNotificationChannel(channel)

// Building the notification.
val builder = Notification.Builder(context, channel.id)
builder.setContentTitle("Warning!")
builder.setContentText("This is a bad notification!")
builder.setSmallIcon(R.drawable.skull)
builder.setColor(ContextCompat.getColor(context, R.color.colorPrimary))
builder.setChannelId(channel.id)

// Posting the notification.
manager.notify(notificationId, builder.build())
}

here in the first-line check the verion of your phone and according to that will get notification Style

builder. small icon and builder.set color(Give color you desire)

Upvotes: 1

Related Questions