如何自定义仅折叠的View android通知?

时间:2019-11-10 02:33:21

标签: android android-notifications

我想在我的应用中显示通知。我正在使用NotificationCompat.BigPictureStyle()。我可以在扩展视图中显示通知。但视图不塌陷。所以我只想修改崩溃通知设计。我已经完成了自定义的notifications_collapsed.xml布局。下面的代码我尝试过,但是没有修改过。

RemoteViews collapsedView = new RemoteViews(context.getPackageName(),
R.layout.notification_collapsed);
collapsedView.setTextViewText(R.id.notification_title_collapsed, title);
collapsedView.setImageViewBitmap(R.id.image_view_collapsed, bitmapImage);
Intent activityIntent = new Intent(context, MainActivity.class);
activityIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
activityIntent.putExtra(ARTICLE_URL, url);
int requestCode = new Random().nextInt();
PendingIntent contentIntent = PendingIntent.getActivity(context, requestCode, activityIntent,0);

NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
Notification notification = new NotificationCompat.Builder(context,
NOTIFICATION_CHANNEL_ID)
                .setSmallIcon(R.drawable.splash_logo)
                .setContentText(title)
                .setCustomContentView(collapsedView)
                .setStyle(new NotificationCompat.BigPictureStyle()
                        .bigPicture(bitmapImage)
                        .bigLargeIcon(null))
                .setPriority(NotificationCompat.PRIORITY_HIGH)
                .setCategory(NotificationCompat.CATEGORY_MESSAGE)
                .setColor(context.getResources().getColor(R.color.colorSplash))
                .setContentIntent(contentIntent)
                .setAutoCancel(true)
                .build();

0 个答案:

没有答案