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

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

问题描述

我用这个简单的code在安卓4.1或更高版本设置的通知。 它运作良好,但我的问题带有SmallIcon和LargeIcon。 据我所知,SmallIcon显示在状态栏和LargeIcon显示在下拉列表中。

  NotificationCompat.Builder建设者=新NotificationCompat.Builder(本);
        builder.setTicker(以下简称股票);
        builder.setContentTitle(标题);
        builder.setContentText(以下简称文);
        builder.setSmallIcon(R.drawable.my_small_icon);
        位图BM = BitmapFactory.de codeResource(getResources(),R.drawable.my_96px_large_icon);
        builder.setLargeIcon(BM);
        NotificationManager纳米=(NotificationManager)getSystemService(NOTIFICATION_SERVICE);
        nm.notify(direct_tag,NOTIF_ALERTA_ID,builder.build());
 

我的问题是接下来的:

  1. 在通知启动,裁剪过大的小图标显示下的北京时间的文字来,而不是显示无尺寸过大它原来的SmallIcon。

  2. 在下拉列表中我看到左边的LargeIcon,这是很好的。但我也看到右侧的小图标,旁边的通知的时间。我不想证明。

任何帮助吗? 先谢谢了。

解决方案
  1. 在我的应用程序提供了较大的(128×128像素)的PNG绘制小图标,它显示了规模化,无需裁剪。是位图文件或者作为XML资源的绘制界定?在XML中,你可以指定显示(如裁剪)的几个方面。仔细检查您的XML或只使用PNG / JPG。

  2. 作为<一个href="http://developer.android.com/reference/android/app/Notification.Builder.html#setSmallIcon%28int%29">Android在Notification.setSmallIcon API文档()明确规定:

      

    设置小图标资源,这将被用来重新present在状态栏上的通知。为扩展视图平台模板将绘制该图标在左,除非大图标也被指定,的在这种情况下,小图标将移至右手侧

AFAIK有没有办法,你可以重写的行为,除非你提供自己的通知模板(通过<一个href="http://developer.android.com/reference/android/app/Notification.Builder.html#setContent%28android.widget.RemoteViews%29">Notification.setContent()

I use 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());

My problem are the next:

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

  2. 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.

Any help? Thanks in advance.

解决方案

  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.

  2. As Android API documentation on Notification.setSmallIcon() clearly states:

    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 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天全站免登陆