gpt4 book ai didi

android - NotificationCompat 4.1 SetSmallIcon 和 SetLargeIcon

转载 作者:IT老高 更新时间:2023-10-28 21:34:48 34 4
gpt4 key购买 nike

我使用这个简单的代码在 Android 4.1 或更高版本中设置通知。它运作良好,但我的问题来自 SmallIcon 和 LargeIcon。我了解 SmallIcon 显示在状态栏中,LargeIcon 显示在下拉列表中。

NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setTicker("The ticker");
builder.setContentTitle("The title");
builder.setContentText("The text");
builder.setSmallIcon(R.drawable.my_small_icon);
Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.my_96px_large_icon);
builder.setLargeIcon(bm);
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
nm.notify("direct_tag", NOTIF_ALERTA_ID, builder.build());

我的问题是:

  1. 启动通知时,“The Ticker”文本旁边会显示一个裁剪过的超大小图标,而不是显示原始的 SmallIcon 而不是超大的。 enter image description here

  2. 在下拉列表中,我看到了左侧的 LargeIcon,这很好。但我也看到右侧的小图标,在通知时间旁边。我不想表现出来。 enter image description here

最佳答案

  1. 在我的应用程序中,我提供了可绘制的大 (128x128 像素) PNG 作为小图标,并且它显示为缩放且没有裁剪。您的可绘制对象是在位图文件中定义的还是作为 XML 资源定义的?在 XML 中,您可以指定显示的多个方面(例如裁剪)。仔细检查您的 XML 或仅使用 PNG/JPG。

  2. 作为 Android API documentation on Notification.setSmallIcon()明确指出:

    Set the small icon resource, which will be used to represent the notification in the status bar. The platform template for the expanded view will draw this icon in the left, unless a large icon has also been specified, in which case the small icon will be moved to the right-hand side.

AFAIK 无法覆盖该行为,除非您提供自己的通知模板(通过 Notification.setContent()

关于android - NotificationCompat 4.1 SetSmallIcon 和 SetLargeIcon,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13847297/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com