我正在开发一个为用户创建通知的应用程序。我希望图标在状态栏中显示为白色,但在下拉通知菜单中显示时显示为蓝色。下面是 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 许可协议
我在这里找到了问题的答案: 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(...)
属性正常工作。