android - 更改 Lollipop 上的通知图标背景

标签 android android-notifications android-5.0-lollipop

我正在浏览 Notifications design pattern ,并且没有找到任何关于通知图标背景的内容。您可能已经注意到,自定义通知只有浅灰色背景。但是像环聊这样的应用程序,或者只是 USB 调试通知的通知图标背景具有自定义颜色。

有没有可能把那个灰色变成别的东西? (以编程方式为特定圆圈的颜色)

See picture

最佳答案

1) 获取颜色

int color = 0xff123456;
int color = getResources().getColor(R.color.my_notif_color);
int color = ContextCompat.getColor(context, R.color.my_notif_color);

2) 设置通知的颜色

NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
...
builder.setColor(color);
Notification notif = builder.build();

颜色仅在 Lollipop 上受到尊重,并且仅影响 小图标的背景。如果显示大图标,则其内容完全由您负责。

来源:NotificationCompat.Builder#setColor(int)

关于android - 更改 Lollipop 上的通知图标背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27343202/

相关文章:

java - 包含 Java 项目作为库

android - 如何通过代码圆化 AlertDialog 的角

java - 在NotificationListenerService中过滤应用程序

android-5.0-lollipop - HAXM 和 Lollipop

android - 具有背景颜色的按钮的 Material 效果

android - 广播接收器不会收到 Intent

Android Studio 3.5.2 - Marketplace 插件未加载

android - Android BigPictureStyle 推送通知中的图像/位图大小应该是多少?

android - 如何删除通知操作

android - 兼容版本的 Android JobScheduler - 备选方案