【问题标题】:Notification icon is round white instead of application icon in lollipop通知图标是圆形的白色,而不是棒棒糖中的应用程序图标
【发布时间】:2016-02-28 05:21:57
【问题描述】:

我已通过以下代码生成本地通知。

Notification notification = new Notification.Builder(context)
    .setAutoCancel(true)
    .setContentTitle("title")
    .setContentText("message")
    .setWhen(System.currentTimeMillis())
    .setSmallIcon(getNotificationIcon())
    .build();



private static int getNotificationIcon() {
    boolean useWhiteIcon = (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP);
    return useWhiteIcon ? R.drawable.icon_loli : R.drawable.ic_launcher;
}

其中 icon icon_loli 是 16*16 白色图标。仍然适用于 21 以下的 api 版本,它工作得很好,但在棒棒糖及更高版本上,它会显示如下图所示的通知

【问题讨论】:

标签: android notifications icons android-5.0-lollipop


【解决方案1】:

这是因为setSmallIcon(),并且在材质设计中它只有黑白,因为主要目的是在顶部栏中显示统一的图标。如果你想要你的标志,你必须使用setLargeIcon(),比如:

Notification notification = new Notification.Builder(context)
    .setAutoCancel(true)
    .setContentTitle("title")
    .setContentText("message")
    .setWhen(System.currentTimeMillis())
    .setSmallIcon(getNotificationIcon())
    .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
    .build();

【讨论】:

  • setLargeIcon() 将应用程序的全尺寸标志作为api lvl低于20?
  • 没问题。您应该从一开始就使用大图标和小图标。状态栏的小图标(设计建议有一个白色的图标,但在棒棒糖之前你可以使用任何你想要的东西。但是由于棒棒糖,操作系统强制你只显示白色的小图标)。大图标将保留您输入的彩色图标。
  • 我放置了白色图标。 16x16。它向我显示了上图中的通知图标,这就是我的问题
  • 小图标用作您显示的图像,因为没有大图标。
  • 通知图标推荐什么wxh,带透明背景?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-10-06
  • 2015-11-01
  • 1970-01-01
  • 2015-08-14
  • 1970-01-01
相关资源
最近更新 更多