【问题标题】:Android Notifications: Small icon not showing with custom imageAndroid 通知:小图标未与自定义图像一起显示
【发布时间】:2020-09-28 13:29:25
【问题描述】:

一开始,我已经浏览了几个讨论这个话题的论坛。例如:Android Push Notifications: Icon not displaying in notification, white square shown instead

如果我将 ic_launcher 徽标作为小图标添加到我的通知中,我会在运行应用程序时看到它。但是,如果我尝试添加自定义图像 (.png) 文件作为徽标,我会看到全白图像。

我不明白的是透明图像/徽标的概念。这已被认为是许多论坛中空白图像的原因。 如果确实如此,那么我该如何生成可以显示的自定义透明图像?需要注意的是,我使用的图像与我的启动徽标 [inside manifest file] 相同,并且它按预期工作。

我的通知对象如下:

notificationBuilder.setOngoing(true)
                .setSmallIcon(R.mipmap.ic_custom_image_icon)
                .setContentTitle("My-Title")
                .setPriority(NotificationManager.IMPORTANCE_MIN)
                .setCategory(Notification.CATEGORY_SERVICE)
                .setStyle(new NotificationCompat.DecoratedMediaCustomViewStyle()
                .setMediaSession(new MediaSessionCompat(this.getApplication(), MY_TAG).getSessionToken()))
                .setColor(0x169AB9)
                .setWhen(System.currentTimeMillis())
                .setOnlyAlertOnce(true)
                .setColorized(true);

【问题讨论】:

  • 希望这会有所帮助 - 我有一个透明图像作为我的通知图标。我在可绘制目录中有我的图标,我的构建器看起来像: notification.setContentTitle("Success") .setContentText("$projectDisplayName") .setSmallIcon(R.drawable.icon) .setColor(ContextCompat.getColor(context, R. color.logo_gold)) .setContentIntent(pendingIntent) .setProgress(0, 0, false) .setOngoing(false) .setAutoCancel(true) .build()
  • @nt95 感谢您的回复。我的问题更多关于如何生成透明图标。假设我有一个 .png 图像,并希望它表现为一个透明图标。我该怎么做呢?是我需要将普通图像转换为透明图像还是简单地将普通图像添加到 R.drawable 并提供您上面介绍的通知参数?
  • 啊,所以你有一个图标,但你想让它透明,对吗?您可以使用在线生成器将图像转换为透明背景。例如,如果您使用堆栈溢出图标,则可以保留灰色和橙色部分并删除白色背景,以便通知仅显示灰色橙色部分
  • @nt95 知道了。我在网上浏览了一种将 png 文件转换为透明背景的方法(例如:onlinepngtools.com/create-transparent-png)并且它有效。感谢您的帮助。

标签: android icons android-notifications


【解决方案1】:

正如怀疑的那样,自定义图像必须具有透明背景。为了实现这一点,可以使用在线转换器。打开透明背景的图片作为Image Asset(在R.drawable下),图片适合作为小图标使用。

【讨论】:

    猜你喜欢
    • 2018-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-02
    • 2021-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多