通知生成器 setSmallIcon “背景”颜色
Posted
技术标签:
【中文标题】通知生成器 setSmallIcon “背景”颜色【英文标题】:NotificationBuilder setSmallIcon "background" color 【发布时间】:2016-07-05 09:59:10 【问题描述】:我正在处理通知。 我会使用下面的代码设置通知图标,但无法设置 图标的背景颜色(突出显示的圆形紫色)。 如果有人愿意分享该方法,那就太好了。
notificationBuilder.setContentTitle(title);
notificationBuilder.setContentText(summaryText);
notificationBuilder.setSmallIcon(R.drawable.icon);
notificationBuilder.setContentIntent(clickIntent);
notificationBuilder.setDeleteIntent(deleteIntent);
[跟进] 嗯...我已经尝试了帖子中建议的方法但是... 图标的背景颜色仍然是“白色”... 我不会设置颜色...
【问题讨论】:
Changing notification icon background on Lollipop的可能重复 我尝试了你的方法,但背景仍然是无色的。有什么线索吗? 【参考方案1】:You can probably create drawable to set icon background and set that as icon
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:right="@dimen/margin_10dp" android:left="@dimen/margin_10dp" android:top="@dimen/margin_10dp" android:bottom="@dimen/margin_10dp">
<shape android:shape="rectangle">
<solid android:color="@color/purple"/>
<padding android:bottom="@dimen/margin_10dp" android:right="@dimen/margin_10dp" android:left="@dimen/margin_10dp" android:top="@dimen/margin_10dp"/>
</shape>
</item>
<item android:drawable="@mipmap/logo" >
</item>
</layer-list>
【讨论】:
【参考方案2】:我想不建议这样做,考虑提供一个你想要的颜色的图标
【讨论】:
以上是关于通知生成器 setSmallIcon “背景”颜色的主要内容,如果未能解决你的问题,请参考以下文章
如何使用 vectorDrawable 作为使用 Android 支持库 23.2 的推送通知的图标? setSmallIcon 给出错误