Android如何在扩展通知布局中删除小图标覆盖层

3
我正在尝试在Lollipop上显示扩展布局的通知,但是我不想让小图标出现在大图标的右下角,就像下面的示例一样。请注意,这仅适用于扩展布局(我尝试了这里提出的解决方案,但似乎不起作用)。 enter image description here 以下是代码:
NotificationCompat.Builder notification = new NotificationCompat.Builder(context);
notification.setContentTitle(reader.getString(Constants.NOTIFICATION_CONFIG_KEY_TITLE));
notification.setContentText(reader.getString(Constants.NOTIFICATION_CONFIG_KEY_TEXT)) ;
notification.setAutoCancel(true) ;
notification.setSmallIcon(Constants.NOTIFICATION_CONFIG_ICON_ID);
notification.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), Constants.NOTIFICATION_CONFIG_ICON_ID));
Notification n = notification.build() ;
的可见性可能在通知构建后进行更改,但我不清楚如何操作。也许有人可以帮忙。 谢谢。

你找到任何解决方案了吗? - undefined
1个回答

0

你可以通过自己构建两个布局(短和展开)来实现这一点。

首先创建2个XML文件并自定义你的布局,然后将它们附加到通知中。 这些布局的根视图应该是LinearLayout

RemoteViews notificationLayout = new RemoteViews(getPackageName(), R.layout.notification_layout); // the small layout

RemoteViews notificationLayoutExpanded = new RemoteViews(getPackageName(), R.layout.notification_layout_large); // the expand layout

NotificationCompat.Builder builder = new NotificationCompat.Builder(this, getString(R.string.notification_channel_id))
                .setSmallIcon(R.drawable.logo)
                .setStyle(new NotificationCompat.DecoratedCustomViewStyle())
                .setCustomContentView(notificationLayout)
                .setCustomBigContentView(notificationLayoutExpanded);


NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
        notificationManager.notify(0, builder.build());

如果你想要动态地为这些布局设置文本或图像(而不是在XML中),你可以按照以下方式进行:

RemoteViews notificationLayout = new RemoteViews(getPackageName(), R.layout.notification_layout);
        
String text = "the text to display";
Bitmap picture = BitmapFactory.decodeResource(getResources(), R.drawable.notification_default_img);;


notificationLayout.setTextViewText(R.id.small_notification_text, text); 
notificationLayout.setImageViewBitmap(R.id.small_notification_img, picture);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接