我正在开发一个为用户创建通知的应用程序。我希望图标在状态栏中显示为白色,但在下拉通知菜单中显示时显示为蓝色。以下是 Google Store 应用执行相同操作的示例。
状态栏中的白色通知:
下拉菜单中的彩色通知:
我怎样才能复制这个?我必须设置哪些属性?
Edit:这是我当前的代码 - 我将图像设置为全白色并具有透明背景,因此它在状态栏中看起来很好,但在通知下拉中,图像仍然是相同的白色:
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));
}
我在这里找到了我的问题的答案:https://stackoverflow.com/a/44950197/4394594 https://stackoverflow.com/a/44950197/4394594
我不完全知道问题是什么,但是通过将我用于图标的巨大 png 放入此工具中通过将生成的图标放入我的 mipmap 文件夹中,我可以获得setColor(...)
属性才能正常工作。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)