NotificationCompat 4.1 SetSmallIcon 和 SetLargeIcon [英] NotificationCompat 4.1 SetSmallIcon and SetLargeIcon

查看:19
本文介绍了NotificationCompat 4.1 SetSmallIcon 和 SetLargeIcon的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I used this simple code to set a Notification in Android 4.1 or higher. It works well, but my problem comes with SmallIcon and LargeIcon. I understand that SmallIcon is shown in the status bar and the LargeIcon is shown in the dropdown list.

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"文本旁边会显示一个裁剪过的超大小图标,而不是在没有超大尺寸的情况下显示原始的小图标.

  1. When the notification is launched, a cropped oversized Small Icon is shown next to "The Ticker" text, instead of showing the original SmallIcon without oversizing it.

在下拉列表中,我看到左侧的大图标,这很好.但我也看到右侧的小图标,在通知时间旁边.我不想表现出来.

In the dropdown list I see the LargeIcon on the left, that's good. But I also see the small icon on the right, next to the time of the notification. I don't want to show that.

推荐答案

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

  1. In my application I provide large (128x128 px) PNG drawable as small icon, and it shows scaled and without cropping. Is your drawable defined in bitmap file or maybe as XML resource? In XML you can specify several aspects of display (e.g. cropping). Double check your XML or use just PNG/JPG.

作为 Android API 文档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()

AFAIK there's no way you can override the behaviour, unless you provide your own notification template (via Notification.setContent()

这篇关于NotificationCompat 4.1 SetSmallIcon 和 SetLargeIcon的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆