我正在使用Firebase云消息向我的Flatter应用程序发送通知.它工作正常,但我的应用图标通知在谷歌Pixel XL上是灰色的.我能看到轮廓,但由于某种原因,它仍然是灰色的.我在不同的文章中读到它与Android SDK级别有关,但Flitter中的Minsdk版本已经是16(少于21),所以我不明白为什么 colored颜色 不会显示在屏幕上.
那么可以用 colored颜色 显示我的应用程序的通知图标吗?
--提前感谢
我正在使用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
文件夹中.
但请记住,此图标必须是white
加transparent background.
对于要着色的某些类型的icons,您需要在您已经在your AndroidManifest.xml
中添加的一些设备集meta-tags
上,并且您的图标必须遵循一些规范(在透明背景中必须为白色).你可以试着生成一个here.试试看.记得把它放在drawable文件夹中,并更新manifest meta-tag
图标名.
也请阅读这SO question篇文章,它加强了我在这里所说的内容.
我已经在运行API Level 27的Pixel 2仿真器上试用过:
希望能有所帮助.