【问题标题】:Android custom notification安卓自定义通知
【发布时间】:2018-06-20 16:39:54
【问题描述】:

如何制作像图片附件一样的自定义通知。enter image description here 你有什么建议或想法吗?

【问题讨论】:

标签: android push-notification android-custom-view


【解决方案1】:

您可以为此使用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 添加为contentNotificationCompat.Builder 类似这样:

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(YOUR_CONTEXT)
.setContent(contentView);

然后创建Notification

Notification mNotification = mBuilder.build();
mNotificationManager.notify(1, mNotification);

这些是简单的步骤,现在您可以根据自己的喜好进行调整。

您也可以在YouTube 或此Tutorial 上查看此示例

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-06-22
    • 2012-02-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-22
    • 2019-02-28
    相关资源
    最近更新 更多