【发布时间】:2017-05-23 15:07:47
【问题描述】:
【问题讨论】:
标签: android notifications
【问题讨论】:
标签: android notifications
BigPictureStyle 通知图像的大小
最小 - 512x256
平衡 - 1024x512
最大 - 2048x1024
从这个答案中得到https://stackoverflow.com/a/33391039/5783417
注意:在较小的设备 (800x480) 中,仍然存在中心裁剪 发生
【讨论】:
试试这个代码
Notification notif = new Notification.Builder(mContext)
.setContentTitle("New photo from " + sender.toString())
.setContentText(subject)
.setSmallIcon(R.drawable.new_post)
.setLargeIcon(aBitmap)
.setStyle(new Notification.BigPictureStyle()
.bigPicture(aBigBitmap))
.build();
【讨论】:
要让通知出现在展开的视图中,首先使用所需的普通视图选项创建一个 NotificationCompat.Builder 对象。接下来,使用展开的布局对象作为参数调用 Builder.setStyle()。
请记住,扩展通知在 Android 4.1 之前的平台上不可用。要了解如何处理 Android 4.1 和更早平台的通知,请阅读处理兼容性部分。
例如,以下代码 sn-p 演示了如何更改在之前的 sn-p 中创建的通知以使用扩展布局:
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.notification_icon)
.setContentTitle("Event tracker")
.setContentText("Events received")
NotificationCompat.InboxStyle inboxStyle =
new NotificationCompat.InboxStyle();
String[] events = new String[6];
// Sets a title for the Inbox in expanded layout
inboxStyle.setBigContentTitle("Event tracker details:");
...
// Moves events into the expanded layout
for (int i=0; i < events.length; i++) {
inboxStyle.addLine(events[i]);
}
// Moves the expanded layout object into the notification object.
mBuilder.setStyle(inboxStyle);
...
// Issue the notification here.
【讨论】: