简体   繁体   English

Android - 如何设置提示通知图标背景颜色(使用 FCM 或默认值)?

[英]Android - How to set heads-up notification icon background color (using FCM or default value)?

I have been able to implement notification icon/text color in the notification center as per Firebase docs.根据 Firebase 文档,我已经能够在通知中心实现通知图标/文本颜色。 However, on Android 11 (or at least, on my Galaxy S20 FE), heads-up notifications (when you just received a notification) shows the icon circled in a blue background (see screenshot), no matter what color I set up in AndroidManifest.xml .然而,在 Android 11 上(或者至少在我的 Galaxy S20 FE 上),抬头通知(当你刚刚收到通知时)显示蓝色背景中的图标(见截图),无论我设置什么颜色AndroidManifest.xml I thought it might be a system thing, but yesterday, I received an Instagram heads-up notification that had a purple background.我以为这可能是系统问题,但昨天,我收到了一条带有紫色背景的 Instagram 提醒通知。 I also received one from Uber Eats, which was green.我还收到了一份来自 Uber Eats 的绿色餐点。 I've searched for around 2 hours and couldn't find anything related to this specific issue (it always gravitated around the classic icon/color AndroidManifest.xml setup).我已经搜索了大约 2 个小时,但找不到与此特定问题相关的任何内容(它总是围绕着经典图标/颜色AndroidManifest.xml设置)。

Here's what I'm talking about:这就是我要说的:

My AndroidManifest.xml related config:我的AndroidManifest.xml相关配置:

<meta-data
    android:name="com.google.firebase.messaging.default_notification_icon"
    android:resource="@mipmap/ic_notification" />
<meta-data
    android:name="com.google.firebase.messaging.default_notification_color"
    android:resource="@color/black"
    tools:replace="android:resource" />

Finally found an explanation.终于找到解释了。

nurassyl (a user that replied to my issue in the RNFB Github) stated that changing the app icon background color worked for him because it gets the dominant color and uses it. nurassyl(一位在 RNFB Github 上回复我的问题的用户)表示更改应用程序图标背景颜色对他有用,因为它获得了主色并使用了它。 At first, I thought he was talking about the notification icon background (which should always be transparent according to guidelines), because he never replied to my question, but he was indeed talking about the main app icon (mipmap ic_launcher icons).起初,我以为他在谈论通知图标背景(根据指南,它应该始终是透明的),因为他从未回答我的问题,但他确实在谈论主应用程序图标(mipmap ic_launcher 图标)。

As for the "dominant color" color statement, that is not entirely true.至于“主导色”的颜色说法,那并不完全正确。 From my tests, it seems like it considers the most dominant non black or white color of your app icon (haven't tried with gray shades, but they might get ignored too).从我的测试来看,它似乎考虑了应用程序图标中最主要的非黑色或白色(尚未尝试使用灰色阴影,但它们也可能会被忽略)。 So if your app icon is a small yellow logo on a black background, even though the black is dominant, it will consider the logo's yellow color as the color to use for the heads-up notification background.因此,如果您的应用程序图标是黑色背景上的黄色小徽标,即使黑色占主导地位,它也会将徽标的黄色视为用于提示通知背景的颜色。

In my case, I thought the problem had fixed itself by a possible software update because the logo color happened to be the same as the notification color stated in the manifest.就我而言,我认为问题已通过可能的软件更新自行解决,因为徽标颜色恰好与清单中所述的通知颜色相同。 For the "problematic" app (the one that made me start this discussion), the logo color of the app icon (blue) and the specified notification color (black) mismatched, hence why I would see a blue background in heads-up notifications, but a black color in the notification center.对于“有问题的”应用程序(让我开始讨论的那个),应用程序图标的徽标颜色(蓝色)和指定的通知颜色(黑色)不匹配,因此我会在抬头通知中看到蓝色背景,但通知中心是黑色。

I hope the explanation and fix is clear to anyone that encounters this thread.我希望遇到此线程的任何人都清楚解释和修复。

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

相关问题 PushSharp Google Cloud Messaging 单挑通知 - PushSharp Google Cloud Messaging Heads-up notification 如何在 AndroidManifest 中使用自定义图标作为 FCM 默认通知图标 - Maui - How to use a custom icon as FCM default notification icon in AndroidManifest - Maui Flutter:FCM后台通知大图标 - Flutter: FCM background notification large icon 我们如何在 android 通知图标中使用多色图标 - How can we use multi color icon in android notification icon Flutter:主屏幕上 iOS 应用程序图标上的通知徽章计数器未显示(使用 FCM) - Flutter: The notification badge counter on the iOS app icon on the home screen is not showing up (using FCM) cordova 后台 FCM 推送通知 (Android) - cordova FCM push notification on background (Android) Android:FCM 通知显示不正确 - Android: FCM notification showing up incorrectly 如何使用 FCM 在 iOS 和 Android 中跟踪收到的通知? - How to track received notification in iOS and Android using FCM? flutter中的FCM自定义通知图标 - FCM Custom Notification Icon in flutter 后台通知 OnClick With FCM Flutter app open an empty activity - Background Notification OnClick With FCM Flutter app open up an empty activity
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM