安卓彩色通知图标

新手上路,请多包涵

我正在开发一个为用户创建通知的应用程序。我希望图标在状态栏中显示为白色,但在下拉通知菜单中显示时显示为蓝色。下面是 Google Store 应用程序执行相同操作的示例。

状态栏中的白色通知:

在此处输入图像描述

下拉菜单中的彩色通知:

在此处输入图像描述

我怎样才能复制这个?我必须设置哪些属性?

编辑: 这是我当前的代码 - 我将图像制作成全白的透明背景,因此它在状态栏中看起来不错,但在通知下拉列表中,图像仍然是相同的白色:

 private NotificationCompat.Builder getNotificationBuilder() {
        return new NotificationCompat.Builder(mainActivity)
                .setDeleteIntent(deletedPendingIntent)
                .setContentIntent(startChatPendingIntent)
                .setAutoCancel(true)
                .setSmallIcon(R.drawable.skylight_notification)
                .setColor(ContextCompat.getColor(mainActivity, R.color.colorPrimary))
                .setContentTitle(mainActivity.getString(R.string.notification_title))
                .setContentText(mainActivity.getString(R.string.notification_prompt));
    }

原文由 Oblivionkey3 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 817
2 个回答

我在这里找到了问题的答案: https ://stackoverflow.com/a/44950197/4394594

我不完全知道问题出在哪里,但是通过将我用于图标的巨大 png 放入此工具中 https://romannurik.github.io/AndroidAssetStudio/icons-notification.html#source.type= image&source.space.trim=1&source.space.pad=0&name=ic_skylight_notification 并将生成的图标放入我的 mipmap 文件夹中,我能够使 setColor(...) 属性正常工作。

原文由 Oblivionkey3 发布,翻译遵循 CC BY-SA 3.0 许可协议

对于从控制台发送的 firebase 通知,您只需将其添加到您的清单中:

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

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

其中 white_logo 是您的应用程序白色徽标,而 custom_color 是您希望为图标和文本着色的颜色。

更多细节在这里: https ://firebase.google.com/docs/cloud-messaging/android/client

原文由 radu_paun 发布,翻译遵循 CC BY-SA 3.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题