简体   繁体   English

通知颜色图标在棒棒糖中不可见,它仅显示白色背景

[英]Notification Colour Icon Not Visible in Lollipop,It Show only a White background

How to visible notification icon without reduce target sdk version to 20 from >20. 如何在不将目标SDK版本从> 20降低到20的情况下显示通知图标。 my Notification Icon is colour icon,not Transparent. 我的通知图标是彩色图标,而不是透明图标。 I used below Code but its not working In case of Lollipop.It showing only White background. 我使用下面的代码,但在棒棒糖的情况下不起作用,它仅显示白色背景。

NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    builder.setSmallIcon(R.drawable.icon_colour);
} else { 
    builder.setSmallIcon(R.drawable.icon_colour);
}

Android Lollipop notification icons are meant to be displayed in white style. Android Lollipop通知图标应以白色样式显示。

There is a documentation for "Android 5.0 behavior changes" 有一个有关“ Android 5.0行为更改”的文档

Notifications are drawn in dark text on white backgrounds (or very light) to match the new widgets of the design material. 通知以白色背景(或非常浅)上的深色文本绘制,以匹配设计材料的新小部件。

This documentation also suggests that you use a color that will be displayed behind the (white) notification icon, where it says: 本文档还建议您使用一种颜色,该颜色将显示在(白色)通知图标的后面,该颜色显示:

Use setColor () to set a highlight color in a circle behind the icon image. 使用setColor()在图标图像后面的圆圈中设置突出显示颜色。

Your solution should be used different rules for each Android version, which you are already using with android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP 您的解决方案应该为每个Android版本使用不同的规则,而您已经在android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP

Try updating your answer with that: 尝试使用以下方法更新答案:

if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    builder.setSmallIcon(R.drawable.icon_no_colour);
    build.setColor(R.color.icon_background_color);
} else { 
    builder.setSmallIcon(R.drawable.icon_colour);
}

setColor() documentantion setColor()文档

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

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