gpt4 book ai didi

Android系统主题为通知图标添加自己的背景

转载 作者:行者123 更新时间:2023-11-29 00:04:42 25 4
gpt4 key购买 nike

我使用 NotificationCompat 创建了一个简单的通知。
以下是我的代码

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mContext);
mBuilder.setSmallIcon(icon)
.setTicker(title)
.setWhen(0)
.setAutoCancel(true)
.setContentTitle(title)
.setStyle(new NotificationCompat.InboxStyle())
.setContentIntent(resultPendingIntent)
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
.setContentText(message);

NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(mNotificationId, mBuilder.build());

这是我设备上的输出。

enter image description here

我的图标没有蓝色渐变背景。该图标是一个 png,仅包含白色 USB 符号。
我怀疑系统正在添加背景。

现在我的问题是,如何防止这种修改。

我的设备正在运行 KitKat 4.4.4

最佳答案

如果您没有指定“大”图标,系统会显示带有标准背景的“小”图标,在您的情况下为蓝色渐变。

您可以使用 setLargeIcon() 设置自定义图像您可以在其中指定显示的位图而不是默认图标。注意:大图标的大小应为 64x64dp。引用this answer举个具体的例子。

从 Android 5.0 开始,您可以选择使用 setColor()这将设置图标后面的背景颜色。但这显然不适用于 Android 4.4。

关于Android系统主题为通知图标添加自己的背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34753417/

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