简体   繁体   English

在Android(在JB上),如何向自定义丰富通知添加操作?

[英]In Android (on JB), how can I add an action to a custom rich notification?

I've been playing with the new rich notificaitons in Jelly Bean, and everything works as expected when I set up a new notificaiton using the templates Notification.BigPictureStyle , Notification.BigTextStyle , or Notification.InboxStyle . 我一直在使用Jelly Bean中新的丰富的通知,当我使用模板Notification.BigPictureStyleNotification.BigTextStyleNotification.InboxStyle设置新的通知时,一切都按预期工作。 I can use the Notification.Builder.addAction() method, and the action buttons show up at the bottom of the extended notification. 我可以使用Notification.Builder.addAction()方法,操作按钮显示在扩展通知的底部。 But when I try to create a cutsom notification using Notification.bigContentView , the action buttons never show up. 但是当我尝试使用Notification.bigContentView创建一个cutom通知时,操作按钮永远不会显示。

Just to clarify, if I never set bigContentView , the buttons do show up. 只是为了澄清,如果我从未设置bigContentView ,那么按钮就会显示出来。 But as soon as that field is set to a custom RemoteViews object, the buttons are gone. 但是只要该字段设置为自定义RemoteViews对象,按钮就会消失。

Does anyone have any ideas on why this is happening? 有没有人对为什么会这样做有任何想法?

The various Big...Style builders create their own bigContentView . 各种Big...Style构建器创建自己的bigContentView If you want your own bigContentView , you have to add the buttons yourself, perhaps by examining the source code to those builders and seeing how they do it. 如果你想要自己的bigContentView ,你必须自己添加按钮,可能是通过检查这些构建器的源代码并了解它们是如何做到的。

When you add your custom bigContentView it will replace the contentview that is created by Notification.BigPictureStyle, Notification.BigTextStyle or Notification.InboxStyle. 当您添加自定义bigContentView时,它将替换由Notification.BigPictureStyle,Notification.BigTextStyle或Notification.InboxStyle创建的内容视图。 As commonsware point out you need to add the button by yourself and thats by creating your own custom remoteView with buttons and then add it as contentView. 正如commonsware所指出的那样,你需要自己添加按钮,然后通过按钮创建自己的自定义remoteView ,然后将其添加为contentView。

You could find a tutorial of how to do this here . 您可以在这里找到如何执行此操作的教程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何创建 Notification.Action 并将其添加到自定义通知 - How can I create a Notification.Action and add it to a custom notification 如何在通知动作中添加动作事件 - how can i add action event on notification action 如何指定Android Wear上未显示通知操作? - How can I specify that an Notification action is not shown on Android Wear? 在Android操作栏中如何添加通知计数? - In Android Action Bar how to add notification count? 丰富的通知操作不可点击 - Rich notification action not clickable 如何通过附加按钮从自定义丰富通知中关闭Android> = 3.0中的通知下拉菜单? - How to close notification drop-down in Android >= 3.0 from custom rich notification with additional button? 如何在Android中使用自定义按钮实现自定义操作栏? - How can I implement custom Action Bar with custom buttons in Android? 如何使用Malcom Android SDK显示自定义通知消息? - How can I display a custom notification message with Malcom Android SDK? 如何在通知FCM Android上添加按钮 - How can I add button on notification FCM Android 如何在Android的状态栏通知中添加超链接 - How can I add an hyperlink in status bar notification in android
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM