簡體   English   中英

如何知道Android Notification大圖片風格的圖片大小?

[英]How to know the picture size in the Android Notification big picture style?

Android大圖片樣式通知

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和早期平台的通知,請閱讀處理兼容性部分。

例如,以下代碼段演示了如何更改在上一個代碼段中創建的通知以使用展開的布局:

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.

您還可以參考此鏈接, 將擴展布局應用於通知

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM