对于此通知,我需要在右侧添加蓝色用户图标。你能告诉我如何实现吗?是否可以使用NotificationBuilder的setter方法之一进行制作?我需要为此通知编写自定义布局吗?
答案 0 :(得分:0)
您必须使用自定义布局进行通知以覆盖默认配置。
(可选)还调用setCustomBigContentView()为展开的通知设置不同的布局。
示例:
// Get the layouts to use in the custom notification
RemoteViews notificationLayout = new RemoteViews(getPackageName(),
R.layout.notification_small);
RemoteViews notificationLayoutExpanded = new RemoteViews(getPackageName(),
R.layout.notification_large);
// Apply the layouts to the notification
Notification customNotification = new NotificationCompat.Builder(context, CHANNEL_ID)
.setSmallIcon(R.drawable.notification_icon)
.setStyle(new NotificationCompat.DecoratedCustomViewStyle())
.setCustomContentView(notificationLayout)
.setCustomBigContentView(notificationLayoutExpanded)
.build();
关注this以获取详细信息
答案 1 :(得分:0)
在您的构建器上添加此行
.setLargeIcon(BitmapFactory.decodeResource(context.resources , R.drawable.your_image))