【发布时间】:2018-06-20 16:39:54
【问题描述】:
如何制作像图片附件一样的自定义通知。enter image description here 你有什么建议或想法吗?
【问题讨论】:
标签: android push-notification android-custom-view
如何制作像图片附件一样的自定义通知。enter image description here 你有什么建议或想法吗?
【问题讨论】:
标签: android push-notification android-custom-view
您可以为此使用RemoteViews
RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.YOUR_CUSTOM_LAYOUT);
contentView.setImageViewResource(R.id.YOUR_IMAGEVIEW_ID, YOUR_ICON);
contentView.setTextViewText(R.id.YOUR_TEXT_VIEW_ID, YOUR_NOTIFICAITON_TEXT);
您可以添加更多参数并对其进行更多自定义,您必须阅读RemoveViews documentation。
然后你创建一个NotificationCompat.Builder 并将contentView 添加为content 从NotificationCompat.Builder 类似这样:
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(YOUR_CONTEXT)
.setContent(contentView);
然后创建Notification
Notification mNotification = mBuilder.build();
mNotificationManager.notify(1, mNotification);
这些是简单的步骤,现在您可以根据自己的喜好进行调整。
【讨论】: