简体   繁体   English

在棒棒糖版本上方的通知中设置小图标

[英]Setting small icon in Notification above lollipop version

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.上面的代码放在一个名为 NotificationService 的 class 中,它扩展了服务。

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. **我的目标不是那样。我想将我的图标设置为其原始颜色,就像在 Dominos 中一样。

Added below code in Android Manifest,在 Android 清单中添加了以下代码,

<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));当我收到推送通知时,我正在启动我的服务以显示如下通知, 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.但是关于这个问题的问题的答案是我上面提到的在 Android Manifest 中放置通知图标的代码。 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.设置颜色将为 h 和 m 设置一种唯一的颜色。 I dont want that.我不想要那个。

There is no solution for this??这个没有解决办法?? No one achieved this??没有人做到这一点??

In the new Android SDKs I think all icons are turned into a plain color.在新的 Android SDK 中,我认为所有图标都变成了纯色。

Look into this question that provides some solutions in notification colors in Lollipop.查看这个问题,它在 Lollipop 的通知 colors 中提供了一些解决方案。

Notification bar icon turns white in Android 5 Lollipop Android 5 Lollipop 中的通知栏图标变为白色

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM