简体   繁体   中英

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. 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 . I thought it might be a system thing, but yesterday, I received an Instagram heads-up notification that had a purple background. I also received one from Uber Eats, which was green. 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).

Here's what I'm talking about:

My AndroidManifest.xml related config:

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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