蜂窝通知 - 如何将largeIcon设置为正确的大小?
我发现自己很好奇为什么Notification.Builder 上的setLargeIcon 方法只接受Bitmap,没有重载来提供资源id。也许这是出于性能原因,但这似乎很奇怪,因为 setSmallIcon 确实接受 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();
遗憾的是,提供的位图在通知中未缩放,因此需要为通知视图提供完全正确的尺寸。
假设我需要提供 LargeIcon 位图的 xhdpi、hdpi、mdpi 和 ldpi 版本,它们需要多大尺寸?我在文档中或在更广泛的网络上搜索后看不到任何提及。
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.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
还没有机会检查它,但 API 11 引入了以下公共尺寸:
应该可以在将其设置在通知上之前使用它们来缩放图像。
Not had a chance to check it yet but API 11 introduced the following public dimens:
Should be able to use those to scale your image before setting it on the notification.
我使用 通知大图标的尺寸 创建缩放位图
然后我设置带有此缩放位图的大图标。
I used the dimensions of the notification's large icon to create a scaled bitmap
And then I set the large icon with this scaled bitamp.