简体   繁体   English

改变在棒棒糖的通知象背景

[英]Changing notification icon background on Lollipop

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. 但是环聊等应用或简单的USB调试通知都会为其通知图标背景提供自定义颜色。

Is there any possibility to change that grey into something else? 有没有可能将那种灰色变成其他东西? (that specific circle's color programmatically) (以编程方式显示特定圆圈的颜色)

见图

1) Obtain Color 1)获得颜色

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

2) Set the Color to the Notification 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 . 颜色仅在Lollipop上受到尊重,仅影响小图标的背景。 If a large icon is shown its contents are entirely your responsibility. 如果显示大图标,则其内容完全由您负责。

Source: NotificationCompat.Builder#setColor(int) 来源: NotificationCompat.Builder #setColor(int)

if you've defined color in colors.xml then in your NotificationBuilder add value as 如果您在colors.xml中定义了颜色,那么在NotificationBuilder中添加值为

.setColor(getResources().getColor(R.color.<YOUR_COLOR>))

That should solve your problem. 那应该可以解决你的问题。 It only affect to background of the icon. 它只影响图标的背景。

getColor(int) has been deprecated on Resources getColor(int)已在Resources弃用

We should now use one of these alternatives: 我们现在应该使用以下替代方案之一:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM