【问题标题】:greyed small icon in header of notification通知标题中的灰色小图标
【发布时间】:2020-01-17 09:07:13
【问题描述】:

我创建简单的通知:

Notification.Builder builder = new Notification.Builder(this);
builder
    .setContentTitle("title")
    .setContentText("this is small text")
    .setSmallIcon(R.drawable.my_small_icon)
    .setTicker("test Ticker")
    .setStyle(new Notification.BigTextStyle().bigText("big mess"));
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {

    NotificationManager notificationManager = getSystemService(NotificationManager.class);
    Bitmap image = BitmapFactory.decodeResource(this.getResources(), R.drawable.icon);
    builder.setLargeIcon(image);
    RemoteViews contentView = builder.createContentView();
    RemoteViews bigContentView = builder.createBigContentView();

    // custom contentView and bigContentView

    builder.setCustomContentView(contentView);
    builder.setCustomBigContentView(bigContentView);
    Notification n = builder.build();
    builder.build();

    notificationManager.notify(1, n);
}

my_small_icon是透明的白色图像,我的问题是不同的this question

它在状态栏中显示我的小图标,与我的徽标相同,但显示的是灰色方块

这个问题发生在 Redmi 4A 7.1 LG K530F 和 Galaxy J7 正常显示。

你能给我建议来解决它吗?

我使用Android Asset Studio,但它无济于事。

【问题讨论】:

    标签: android android-notifications compatibility


    【解决方案1】:

    你可以去你的项目资源文件夹

    res=>drawable 文件夹=>在 drawable 文件夹中单击鼠标右键 => 打开弹出窗口 => 新建 => 选择图像资源 => 打开资产工作室 => 选择图标类型 => 通知图标 => 并创建并将该图标设置为通知

    【讨论】:

      【解决方案2】:

      首先,您必须检查您用于通知的图像是否具有透明背景。

      其次,您必须保持每个密度的大小

      MDPI - 24 x 24  (drawable-mdpi)
      HDPI - 36 x 36  (drawable-hdpi)
      XHDPI - 48 x 48  (drawable-xhdpi)
      XXHDPI - 72 x 72  (drawable-xxhdpi)
      XXXHDPI - 96 x 96  (drawable-xxxhdpi)                             
      

      在此处关注link 根据Android文档 - “更新或删除涉及颜色的资产。系统会忽略操作图标和主通知图标中的所有非 Alpha 通道。您应该假设这些图标仅是 Alpha 版。系统以白色绘制通知图标,以深灰色绘制操作图标。” 现在这很容易被忽略,我已经看到许多应用程序都在应用程序商店中,有成千上万的用户没有遵循上述指南。 因此,让我详细解释一下如何通过单击几下将通知图标转换为对 Android 友好的图标。 在您最喜欢的图像编辑器中打开您的图标文件。将您不想显示的图像的所有部分转换为透明像素。所有颜色和非透明像素均以白色显示。

      【讨论】:

      • 谢谢,我用了那个尺寸,但对我没有帮助
      • @Hongarc 你用过透明背景的图片并在清单中声明了吗?
      • 如何在manifest文件中声明?我没有对清单文件进行更改。你的意思是android:iconapplication 标签?
      猜你喜欢
      • 2022-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-22
      • 1970-01-01
      • 2018-10-23
      • 2018-01-01
      相关资源
      最近更新 更多