在棒棒糖版本以上的通知中设置小图标 [英] Setting small icon in Notification above lollipop version

查看:152
本文介绍了在棒棒糖版本以上的通知中设置小图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了平视通知.如下所示,

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());

上面的代码放置在名为NotificationService的类中,该类扩展了Service.

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.

**我的目标不是那样.我想像在Domino中一样设置图标的原始颜色.

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

在Android清单中添加了以下代码,

Added below code in Android Manifest,

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

当我收到推送通知时,我将启动我的服务以显示如下所示的通知, startService(new Intent(this,NotificationService.class));

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

但是我收到的通知图标为灰色,而不是原始颜色. 还搜索了很多站点和堆栈问题.但是,有关此问题的答案是我上面提到的在Android Manifest中放置通知图标的代码.即使我按照答案进行操作,也无法将通知图标设置为像多米诺骨牌一样. 我无法找到问题所在. 搜索大多数已发布的堆栈问题.但是找不到适合我问题的答案.

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...

下面是通知即时消息.

您可以看到我的通知图标由两个文本组成.而这两个包含两种不同的颜色.那就是我想要达到的目标.但是我只得到灰色.设置颜色只会为h和m设置一种唯一的颜色.我不要.

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??

推荐答案

在新的Android SDK中,我认为所有图标都变成了纯色.

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

研究这个问题,为Lollipop中的通知颜色提供一些解决方案.

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

Android 5 Lollipop中的通知栏图标变为白色

这篇关于在棒棒糖版本以上的通知中设置小图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆