蜂窝通知-如何将largeIcon设置为正确的大小? [英] Honeycomb notifications - How to set largeIcon to the right size?

查看:329
本文介绍了蜂窝通知-如何将largeIcon设置为正确的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现自己很好奇为什么Notification.Builder上的setLargeIcon方法只接受一个位图,而没有提供资源ID的重载.也许是出于性能方面的考虑而完成的,但由于setSmallIcon确实接受res可绘制的ID,因此似乎很奇怪.

I find myself curious why the setLargeIcon method on Notification.Builder only accepts a Bitmap, with no overload to provide a resource id. Perhaps it was done for performance reasons, but it seems odd as setSmallIcon does accept a res drawable id.

Notification.Builder builder = new Notification.Builder(application);
// ....
builder.setLargeIcon(iconBitmap);  // Requires a Bitmap
builder.setSmallIcon(iconResId);   // Requires a drawable resource ID
Notification notification = builder.getNotification();

遗憾的是,通知中未缩放提供的位图,因此需要为通知视图提供正确大小的位图.

Sadly the bitmap provided is not scaled in the notification, so the Bitmap needs to be provided exactly the right size for the notification view.

假设我需要提供largeIcon位图的xhdpi,hdpi,mdpi和ldpi版本,它们的大小应该是多少?我看不到文档中提到的任何内容,也没有在搜索更广泛的网络后看到任何内容.

Assuming I need to provide xhdpi, hdpi, mdpi and ldpi versions of the largeIcon bitmap, what sizes do they need to be? I can see no mention in the docs, or after scouring the wider web.

推荐答案

尚未有机会对其进行检查,但是API 11引入了以下公共维度:

Not had a chance to check it yet but API 11 introduced the following public dimens:

  • notification_large_icon_height
  • notification_large_icon_width

在通知上设置图像之前,应该能够使用这些图像来缩放图像.

Should be able to use those to scale your image before setting it on the notification.

这篇关于蜂窝通知-如何将largeIcon设置为正确的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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