我正在使用Firebase云消息向我的Flatter应用程序发送通知.它工作正常,但我的应用图标通知在谷歌Pixel XL上是灰色的.我能看到轮廓,但由于某种原因,它仍然是灰色的.我在不同的文章中读到它与Android SDK级别有关,但Flitter中的Minsdk版本已经是16(少于21),所以我不明白为什么 colored颜色 不会显示在屏幕上.

那么可以用 colored颜色 显示我的应用程序的通知图标吗?

--提前感谢

推荐答案

Here你可以读到:

Customize default notification

Custom default icon

通过设置自定义默认图标,可以指定使用的图标

Custom default Color

You can also define what color is used with your notification. Different android versions use this settings in different ways: Android < N use this as background color for the icon. Android >= N use this to color the icon and the app name.

试着把它放进你的AndroidManifest.xml

<!-- Set custom default icon. This is used when no icon is set for incoming notification messages. -->
<meta-data
    android:name="com.google.firebase.messaging.default_notification_icon"
    android:resource="@drawable/ic_stat_ic_notification" />
<!-- Set color used with incoming notification messages. This is used when no color is set for the incoming notification message.  -->
<meta-data
    android:name="com.google.firebase.messaging.default_notification_color"
    android:resource="@color/colorAccent" />

你可以找到更多信息here.

你还需要给你的colorAccent下定义.您可以在res文件夹中创建colors.xml文件,如下所示:

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

在这个文件夹中:/android/app/src/main/res/values

此外,图标必须位于drawable文件夹中.

但请记住,此图标必须是whitetransparent background.

对于要着色的某些类型的icons,您需要在您已经在your AndroidManifest.xml中添加的一些设备集meta-tags上,并且您的图标必须遵循一些规范(在透明背景中必须为白色).你可以试着生成一个here.试试看.记得把它放在drawable文件夹中,并更新manifest meta-tag图标名.

也请阅读这SO question篇文章,它加强了我在这里所说的内容.

我已经在运行API Level 27的Pixel 2仿真器上试用过:

enter image description here

希望能有所帮助.

Flutter相关问答推荐

try 使用共享首选项存储用户数据时出错

飘动的文本用/字符绕转

在Flutter 中创建自定义Snackbar类

为什么Build_Runner的输出为0?

在Flutter 中每次点击按钮时都很难调用自定义函数

应为Map String,dynamic类型的值,但得到的值为type()= Map String,dynamic'

Flutter 日期时间格式

无法应用插件com.chaquo.python

如何给按钮的边框半径?

网页浏览器不支持鼠标滚动的行项目

文本溢出文本框 - Flutter

Flutter 中的 Provider 不会在第一次构建 App 时返回

是否可以在 flutter 应用程序中使用 jetpack compose?

如何在 flutter 中使用带有有效负载数据的重定向来执行 firebase 推送通知.?

在 Flutter 中使用 HardwareKeyboard 时所有键都没有响应

在不丢失游戏状态的情况下从 Flame 游戏导航到 Flutter 小部件

容器在发布模式下显示灰色框(抖动)

出现错误;运算符[]不是为对象类型定义的?功能()'

我一直在try 创建按钮以导航到第二页,但不知何故 RaisedButton 功能无法正常工作

如何从dart 中的当前日期时间中减go 1 天?