问题描述
我希望通知徽标的颜色是通知中的本机颜色,但与状态栏中的所有其他颜色(灰色)相同。
请问我该怎么做。这是我目前所拥有的。
安卓清单
<Meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@mipmap/logo_native" />
<Meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="@color/colorAccent" />
COLORS.XML
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorAccent">#BFBFBF</color>
</resources>
非常感谢任何帮助。 谢谢
解决方法
您可以使用 setColor 更改通知颜色,如下所示,徽标必须是透明的背景以反映颜色
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
int notification_ID = 0;
String channel_ID = "xxx444";
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context,channel_ID)
.setColor(Color.BLACK)
.setSmallIcon(R.drawable.ic_notification)
.setContentText("Review Reminder")
.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE)
.setAutoCancel(true)
.setChannelId(channel_ID)
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
mNotificationManager.notify(notification_ID,mBuilder.build());
NotificationChannel channel = new NotificationChannel(channel_ID,"Review Reminder",NotificationManager.IMPORTANCE_HIGH);
channel.enableLights(true);
channel.enableVibration(true);
channel.setVibrationPattern(new long[]{100,200,300,400,500,400});
mBuilder.setChannelId(channel_ID);
mNotificationManager.createNotificationChannel(channel);
} else {
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context,channel_ID)
.setColor(Color.BLACK)
.setSmallIcon(R.drawable.ic_notification)
.setContentText("Review Reminder")
.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE)
.setAutoCancel(true);
mNotificationManager.notify(notification_ID,mBuilder.build());
}
,
Firebase 支持 2 种消息,“数据”和“通知”。您必须使用“数据”格式并构建自己风格的通知,包括图标的颜色。在此处查看详细信息:https://firebase.google.com/docs/cloud-messaging/android/receive