對不起,對於遲到的答覆..其實我也面臨同樣的問題,並得到了解決方案,所以我認爲它可以幫助其他用戶。
因爲我們不能使用NotificationCompat.Builder
的兩個BigTextStyle
和BigPictureStyle
方法比,我們可以創建CustomView
。
我們可以使用setCustomBigContentView(RemoteViews)
方法NotificationCompat.Builder
並創建我們自己的視圖來顯示大圖像與大文本。
請檢查下面的代碼吧: -
PendingIntent pendingIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(), i,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this);
notificationBuilder.setContentTitle("YOUR_APP_NAME");
notificationBuilder.setContentText(body);
notificationBuilder.setTicker("YOUR_APP_NAME");
notificationBuilder.setAutoCancel(true);
notificationBuilder.setSound(defaultSoundUri);
notificationBuilder.setCustomBigContentView(remoteView("YOUR_MESSAGE_TO_SHOW"));///IT IS THE MAIN METHOD WHICH WE USE TO INFLATE OR CREATE THE CUSTOM VIEW
notificationBuilder.setSmallIcon(getNotificationIcon(notificationBuilder));
notificationBuilder.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify((int) System.currentTimeMillis(), notificationBuilder.build());
下面是我們從setCustomBigContentView()
方法稱爲
private RemoteViews remoteView(String message)
{
RemoteViews views;
views = new RemoteViews(getPackageName(), R.layout.YOUR_LAYOUT_HERE);
views.setImageViewBitmap(R.id.YOUR_BIG_IMAGE_ID_FROM_LAYOUT, bitmap);
views.setImageViewBitmap(R.id.YOUR_APP_ID_FROM_LAYOUT, BitmapFactory.decodeResource(getResources(), R.drawable.APP_ICON_OF_YOUR_APP));
views.setTextViewText(R.id.YOUR_BIG_TEXTVIEW_ID_FROM_LAYOUT, message);
return views;
}
我創建了自定義通知喜歡它
的RemoteViews
關於此主題的任何更新? 使用BigPictureStyle BigTextStyle ... –
是的,它很容易。創建自己的通知佈局! 你可以設計你的XML並將其添加到通知。 欲瞭解更多詳情: http://developer.android.com/guide/topics/ui/notifiers/notifications.html#CustomNotification –