Android 系统主题为通知图标添加自己的背景
Android system theme adding its own background to the icon of notification
我使用 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());
这是我设备上的输出。
我的图标没有蓝色渐变背景。该图标是一个 png,仅包含白色 USB 符号。
我怀疑系统正在添加背景。
现在我的问题是,如何防止这种修改。
我的设备是 运行 KitKat 4.4.4
如果您不指定 'large' 图标,系统会显示带有标准背景的 'small' 图标,在您的情况下为蓝色渐变。
您可以使用 setLargeIcon()
where you can specify a Bitmap that is shown instead of the default icon. Note: The large icon should have a size of 64x64dp. Refer to this answer 设置自定义图像作为具体示例。
从 Android 5.0 开始,您可以选择使用 setColor()
,它将设置图标后面的背景颜色。但这显然不适用于 Android 4.4.
我使用 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());
这是我设备上的输出。
我的图标没有蓝色渐变背景。该图标是一个 png,仅包含白色 USB 符号。
我怀疑系统正在添加背景。
现在我的问题是,如何防止这种修改。
我的设备是 运行 KitKat 4.4.4
如果您不指定 'large' 图标,系统会显示带有标准背景的 'small' 图标,在您的情况下为蓝色渐变。
您可以使用 setLargeIcon()
where you can specify a Bitmap that is shown instead of the default icon. Note: The large icon should have a size of 64x64dp. Refer to this answer 设置自定义图像作为具体示例。
从 Android 5.0 开始,您可以选择使用 setColor()
,它将设置图标后面的背景颜色。但这显然不适用于 Android 4.4.