Android系统提供了扩展功能,用于不同的通知样式。您需要一个显示用户可以选择的选项列表的视图。因此,您需要创建一个自定义视图并使用您的选项填充它。
您可以使用Android通知系统提供的Notification.DecoratedCustomViewStyle()
设置自定义视图。
如果您想要折叠和展开视图的不同外观,则可以使用以下方法进行设置 -
setStyle(new Notification.DecoratedCustomViewStyle())
.setCustomContentView(remoteViews)
.setCustomBigContentView(bigRemoteView);
您需要为布局中指定的所有选项添加不同的待处理意图。
例如 -
RemoteViews firstOption = ....;
Intent firstOptionIntent = // add some argument in this intent which depicts this option
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, flags);
setOnClickPendingIntent(R.id.<option_layout_id>, pendingIntent);
// 对于其他选项同样适用
RemoteViews secondOption = ....;
要在通知操作单击时添加下拉列表,您需要使用2个不同的布局,一个用于折叠视图,另一个用于展开视图 -
Notification customNotification = new NotificationCompat.Builder(context, CHANNEL_ID)
.setSmallIcon(R.drawable.notification_icon)
.setStyle(new NotificationCompat.DecoratedCustomViewStyle())
.setCustomContentView(notificationLayout) // collapsed view layout
.setCustomBigContentView(notificationLayoutExpanded) // expanded view layout
.build();
这是 Android Oreo 中所有通知的标准设置。
对于所有通知,您都可以选择将其暂停。如果您想要在老旧的 Android 设备上实现相同的 UI,您可以直接查看 Android Oreo 系统 UI 的源代码,从中获取 Android 8 及以上版本中的暂停选项。
检查此字符串的使用
<!-- Notification: Snooze panel: message indicating how long the notification was snoozed for. [CHAR LIMIT=100]-->
1520 <string name="snoozed_for_time">Snoozed for <xliff:g id="time_amount" example="15 minutes">%1$s</xliff:g></string>
http://androidxref.com/8.1.0_r33/xref/frameworks/base/packages/SystemUI/res/values/strings.xml#1519