更改棒棒糖上的通知图标背景 [英] Changing notification icon background on Lollipop

查看:97
本文介绍了更改棒棒糖上的通知图标背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在经历通知设计模式,但没有找到任何有关通知图标背景的内容.您可能已经注意到,自定义通知只有浅灰色的背景.但是环聊或简单的USB调试通知之类的应用会为其通知图标背景设置自定义颜色.

I was going through the Notifications design pattern, and didn't find anything that talks about notification icon background. As you probably noticed, there is only a light grey background for custom notifications. But apps like Hangouts, or simply the USB Debugging notification has a custom color for their notification icon background.

是否有可能将灰色更改为其他颜色? (以编程方式指定特定圆圈的颜色)

Is there any possibility to change that grey into something else? (that specific circle's color programmatically)

推荐答案

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();

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

The color is respected only on Lollipop and only affects background of the small icon. If a large icon is shown its contents are entirely your responsibility.

来源: NotificationCompat.Builder#setColor(int)

这篇关于更改棒棒糖上的通知图标背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆