gpt4 book ai didi

android - 如何在 Lollipop 和 Android M 中不显示通知的正确小图标

转载 作者:行者123 更新时间:2023-11-29 20:28:44 25 4
gpt4 key购买 nike

我正在创建一个应用程序,我能够正确显示通知,但是小图标没有显示,正如我在可绘制文件夹中提到的那样,图标被白色遮盖了。任何人都可以帮助我,我怎样才能让图标正确显示。

下面是我的通知代码:

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中提到的icon如下图所示:

[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 这样的图标,并在您想添加颜色的任何地方制作一些透明的部分。

Iconography

您可以使用添加颜色

.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."

希望对您有所帮助!

关于android - 如何在 Lollipop 和 Android M 中不显示通知的正确小图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32267626/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com