Setting small icon in Notification above lollipop version

给你一囗甜甜゛ 提交于 2020-07-08 07:09:14

问题


I have created heads up notification. As like below,

NotificationCompat.Builder notification = new NotificationCompat.Builder(this, channelId)
                .setContentTitle("Message")
                .setContentText("Recieved Successfully")
                .setContentIntent(pendingIntent)
                //.setColor(ContextCompat.getColor(this, R.color.green))
                .setSmallIcon(R.drawable.notification_icon)
                .setDefaults(Notification.DEFAULT_ALL)
                .setContentIntent(pendingIntent)
   .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
                .setAutoCancel(true)
                .setPriority(NotificationCompat.PRIORITY_HIGH);
        manager.notify(m,notification.build());

Above code placed inside a class named NotificationService which extends Service.

I can able to set color using below code,

setColor(ContextCompat.getColor(this, R.color.colorAccent))

But using that able to set only a unique color.

**My goal is not that.I want to set my icon with its original color as like in Dominos.

Added below code in Android Manifest,

<meta-data
            android:name="com.google.firebase.messaging.default_notification_icon"
            android:resource="@drawable/notification_icon" />

When I am getting push notification I am starting my Service for displaying notification like below, startService(new Intent(this,NotificationService.class));

But Im getting notification icon with grey color, not in original color. Also searched a lot sites and stack question. But the answer for the question regarding this problem is the code for placing notification icon in Android Manifest which I mentioned above. Eventhough I followed the answers, couldn't set the notification icon as like dominos. I didnt able to find where it is going wrong. Searched most of the stack questions posted. But not able to find suitable answer for my problem.

Anybody please help me...

Below is the Notification Im getting.

As you can see my notification icon consist of two text. And those two contains two different color. Thats what I am trying to achieve. But I am getting only grey color. Setting color will set only one unique color for both h and m. I dont want that.

There is no solution for this?? No one achieved this??


回答1:


In the new Android SDKs I think all icons are turned into a plain color.

Look into this question that provides some solutions in notification colors in Lollipop.

Notification bar icon turns white in Android 5 Lollipop



来源:https://stackoverflow.com/questions/62422988/setting-small-icon-in-notification-above-lollipop-version

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!