简体   繁体   English

如何在棒棒糖和Android M中未显示正确的小图标以进行通知

[英]how to display proper small icon for notification is not getting displayed in Lollipop and Android M

I am creating an application, I am able to display notification properly, but small icon is not getting displayed as I have mentioned it in the drawable folder, The icon is getting masked with white color. 我正在创建一个应用程序,能够正确显示通知,但是没有显示小图标,正如我在drawable文件夹中提到的那样,该图标被白色蒙版了。 Can any one help me, how can I get the icon to display properly. 谁能帮我,如何使图标正确显示。

Below is my notification code: 以下是我的通知代码:

nb = new NotificationCompat.Builder(context)
        .setContentTitle(contentTitle)
        .setContentText(contentText)
        .setSmallIcon(icon)
        .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.micon_notification))
        .setWhen(when)
        .setContentIntent(contentIntent)
        .setAutoCancel(true)
        .setOnlyAlertOnce(true)
        .setTicker(tickerText)
        .setColor(Color.RED);

The icon mentioned in drawable is as shown below: drawable中提到的图标如下所示:

[1]: http://i.stack.imgur.com/ggYCY.png

That complete red color present inside the image is getting vanished and icon is getting displayed with complete white color. 图像中存在的完全红色消失了,并且图标显示为完全白色。 All suggestions are welcome. 欢迎所有建议。

This is the code Android uses to display notification icons: 这是Android用于显示通知图标的代码:

if (entry.targetSdk >= Build.VERSION_CODES.LOLLIPOP) {
    entry.icon.setColorFilter(mContext.getResources().getColor(android.R.color.white));
} else {
    entry.icon.setColorFilter(null);
}

For that you've to make icon like Silhouette and make some section Transparent wherever you wants to add your Colors. 为此,您必须将“轮廓”之类的图标设置为透明,并在要添加颜色的位置使某些部分透明。

影像学

You can add your color using 您可以使用添加颜色

.setColor(your_color_resource_here)

NOTE : setColor is only available in Lollipop so, you've to check OSVersion 注意:setColor仅在Lollipop中可用,因此,您必须检查OSVersion

if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
    Notification notification = new Notification.Builder(context)
    ...
} else {
    // Lollipop specific setColor method goes here.
    Notification notification = new Notification.Builder(context)
    ...
    notification.setColor(your_color)
    ...            
}

Look at the documentation: http://developer.android.com/design/style/iconography.html 查看文档: http : //developer.android.com/design/style/iconography.html

there are words: 有话:

"Notification icons must be entirely white. Also, the system may scale down and/or darken the icons." “通知图标必须完全为白色。此外,系统可能会缩小和/或加深图标。”

I hope it helps! 希望对您有所帮助!

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

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