如何在 Lollipop 和 Android M 中不显示通知的正确小图标
how to display proper small icon for notification is not getting displayed in Lollipop and Android M
我正在创建一个应用程序,我能够正确显示通知,但是小图标没有显示,正如我在可绘制文件夹中提到的那样,图标被白色遮盖了。谁能帮帮我,怎样才能让图标正常显示呢
下面是我的通知代码:
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);
drawable中提到的图标如下图:
[1]: http://i.stack.imgur.com/ggYCY.png
图像中的全红色正在消失,图标显示为全白色。欢迎所有建议。
这是 Android 用于显示通知图标的代码:
if (entry.targetSdk >= Build.VERSION_CODES.LOLLIPOP) {
entry.icon.setColorFilter(mContext.getResources().getColor(android.R.color.white));
} else {
entry.icon.setColorFilter(null);
}
为此,您必须制作像 Silhouette 这样的图标,并在您想添加颜色的任何地方制作一些透明部分。
您可以使用
添加颜色
.setColor(your_color_resource_here)
注意: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)
...
}
查看文档:http://developer.android.com/design/style/iconography.html
有字:
"Notification icons must be entirely white. Also, the system may scale
down and/or darken the icons."
希望对您有所帮助!
我正在创建一个应用程序,我能够正确显示通知,但是小图标没有显示,正如我在可绘制文件夹中提到的那样,图标被白色遮盖了。谁能帮帮我,怎样才能让图标正常显示呢
下面是我的通知代码:
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);
drawable中提到的图标如下图:
[1]: http://i.stack.imgur.com/ggYCY.png
图像中的全红色正在消失,图标显示为全白色。欢迎所有建议。
这是 Android 用于显示通知图标的代码:
if (entry.targetSdk >= Build.VERSION_CODES.LOLLIPOP) {
entry.icon.setColorFilter(mContext.getResources().getColor(android.R.color.white));
} else {
entry.icon.setColorFilter(null);
}
为此,您必须制作像 Silhouette 这样的图标,并在您想添加颜色的任何地方制作一些透明部分。
您可以使用
添加颜色.setColor(your_color_resource_here)
注意: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)
...
}
查看文档:http://developer.android.com/design/style/iconography.html
有字:
"Notification icons must be entirely white. Also, the system may scale down and/or darken the icons."
希望对您有所帮助!