Android 通知有一个彩色图标,而不是变成白色

问题描述 投票:0回答:7

我的 Android 应用使用 Firebase Cloud Messaging 进行通知。当通知进来时,该图标不会像其他图标一样变成白色。

我正在使用

targetSdkVersion 23

我的清单中有这个:

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

PNG 文件位于

android/app/src/main/res/drawable/notification_icon.png

如何让图标正常显示?

android firebase firebase-cloud-messaging
7个回答
1
投票

看一下 SVG 设计器中的图标。您是否为其分配了颜色或者显示为白色?


1
投票

按照 Will Jones 的建议,解决方案是使用 SVG 文件并将其转换为 XML:http://inloop.github.io/svg2android/。然后我将文件复制到

android/app/src/main/res/drawable/notification_icon.xml
并删除了旧的 PNG 文件。

图标现在可以正确呈现。


0
投票

尝试这个

然后将资源设置为白色: android:resource="@color/google_white"


0
投票

一种选择是使用通知图标生成器


0
投票

我有点晚了,但请尝试将其添加到您的清单中

    <meta-data
        android:name="com.google.firebase.messaging.default_notification_color"
        android:resource="@color/notification_icon_color" />

0
投票

就我而言,我有一个离子项目,所以@Flavien的答案是正确的,但不是:

android/app/src/main/res/drawable/notification_icon.xml

您需要编写不带.xml后缀的内容,如下所示:

android/app/src/main/res/drawable/notification_icon

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

您应该提供具有透明背景的png。

© www.soinside.com 2019 - 2024. All rights reserved.