扑火基地推送通知图标

问题描述

我制作了一个应用程序,并实现了推送通知,并且可以正常工作,但是我尝试使用image.png更改认图标,但是它没有按我预期的方式工作。这是我的通知的样子:

enter image description here

我希望我的图标看起来像这样:

enter image description here

我在Android清单中添加了以下内容

<!-- Add custom icon to the notifications -->
<Meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@drawable/ic_notifications" />
<!-- Change the color of the icon -->
<Meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="@color/colorPrimary" />

我不知道我做错了什么,但是您能帮我吗?

解决方法

android:resource 标签中的 folder (@name/meta-data) 是指通知图标应该位于 android\app\src\main\res\ folder-size\ name.png.

对于您的确切范围,您需要特定位置的 drawable-size 文件夹,其中包含名为 ic_notifications 的 png。我建议您使用此 amazing tool 以正确的布局(透明上的白色)生成所有必需的图标。

因为您的通知也有颜色,所以您必须在包含您的 colors.xmlandroid/app/src/main/res/values 中添加 colorPrimary

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="colorPrimary">#FFFFFF</color>
</resources>

额外: android:icon 标签中的 application 指的是应用程序的图标。只想添加这条额外的信息,因为当找到的示例非常相似时,一开始可能会令人困惑。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...