2017年5月30日 星期二

Android Notification 的幾種樣式

推播內容加上一張小圖片




推播內容加上大圖加上下方的按鈕



//載入bitmap
Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.mipmap.user);
//設定大圖Style
NotificationCompat.BigPictureStyle bitStyle = new NotificationCompat.BigPictureStyle();
bitStyle.bigPicture(largeIcon);
//設定按鈕
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.addAction(R.mipmap.ic_launcher, "Reply", replyIntent)



推播內容使用客製的View



//new RemoteViews 載入客製layout
RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.notification_view);
//設定使用CustomView
notificationBuilder.setCustomBigContentView(remoteViews);



客製view
notification_view.xml


完整程式碼:https://github.com/evanchen76/PushNotificationSample

參考:https://developer.android.com/guide/topics/ui/notifiers/notifications.html

沒有留言:

張貼留言