在安卓通知中,操作按钮不可见。

3
我试图定制 Android 通知,就像这样。
enter image description here
对于 API23 以上,一切都正常。对于 API23 以下,操作按钮不可见。我不知道我的代码有什么问题。
以下是我的示例代码,适用于 API23 以下:
RemoteViews expandedView = createMultiRemoteViews(context,
                R.layout.notification_multiview_b23, icon, "Custom notification", "This is a custom layout", leftImage, rightImage, "09:10", "16:23");

expandedView.setOnClickPendingIntent(R.id.left_image, leftImageIntent);
expandedView.setOnClickPendingIntent(R.id.right_image, rightImageIntent);

NotificationCompat.Action addToWatchListAction = new NotificationCompat.Action.Builder(R.drawable.ic_bookmark_border_black_24dp,
                LABEL_ADD_TO_WATCH_LIST, addToWatchList).build();

NotificationCompat.Builder builder = createNotificationBuider(context, "Custom notification", "This is a custom layout", icon);
builder.addAction(addToWatchListAction);
builder.setCustomBigContentView(expandedView);

showNotification(context, builder.build(), MULTI_NOTI_ID);

你尝试过哪个Android版本?NotificationCompat.Action官方文档指出在Android 4.1之前不起作用。 - rala
@rala 我尝试了 Android 版本 6.0.1,我的 minSDK 版本是 16。 - khaleel_jageer
1个回答

0

API 24 以下版本不支持通知操作,可能是兼容性问题。为了支持向后兼容,请使用支持库的 NotificationCompat 类。 这里有官方文档的 链接 和支持库类的 链接


我使用了NotificationCompact类。 - khaleel_jageer
并非所有通知功能都适用于特定版本,即使设置它们的方法在支持库类NotificationCompat.Builder中。例如,动作按钮依赖于扩展通知,仅在Android 4.1及更高版本上显示,因为扩展通知本身仅在Android 4.1及更高版本上可用。 - Sky Kelsey

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