【问题标题】:Android system theme adding its own background to the icon of notificationAndroid系统主题为通知图标添加自己的背景
【发布时间】:2016-01-13 05:09:22
【问题描述】:

我使用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());

这是我设备上的输出。

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

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

我的设备正在运行 KitKat 4.4.4

【问题讨论】:

    标签: android notifications android-notifications notification-icons


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-01
      • 1970-01-01
      • 2016-08-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多