我创建了平视通知。如下所示,
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。
我可以使用以下代码设置颜色
setColor(ContextCompat.getColor(this, R.color.colorAccent))
但是使用该功能只能设置一种独特的颜色。
**我的目标不是那样。我想像在Domino中一样设置图标的原始颜色。
在Android Manifest中添加了以下代码,
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@drawable/notification_icon" />
当我收到推送通知时,我将启动服务以显示如下所示的通知, startService(new Intent(this,NotificationService.class));
但是我收到的通知图标为灰色,而不是原始颜色。 还搜索了很多站点和堆栈问题。但是,有关此问题的答案是我上面提到的在Android Manifest中放置通知图标的代码。即使我按照答案进行操作,也无法像多米诺骨牌一样设置通知图标。 我无法找到问题所在。 搜索发布的大多数堆栈问题。但是找不到适合我问题的答案。
任何人请帮助我...
下面是通知即时消息
您可以看到我的通知图标由两个文本组成。而这两个包含两种不同的颜色。那就是我想要达到的目标。但是我只得到灰色。设置颜色只会为h和m设置一种唯一的颜色。我不要。
对此没有解决方案吗?没有人实现这一目标吗?
答案 0 :(得分:0)
在新的Android SDK中,我认为所有图标都变成了纯色。
研究这个问题,为Lollipop中的通知颜色提供一些解决方案。