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

回眸只為那壹抹淺笑 提交于 2019-12-12 10:53:56

问题


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. I can use the Notification.Builder.addAction() method, and the action buttons show up at the bottom of the extended notification. But when I try to create a cutsom notification using Notification.bigContentView, the action buttons never show up.

Just to clarify, if I never set bigContentView, the buttons do show up. But as soon as that field is set to a custom RemoteViews object, the buttons are gone.

Does anyone have any ideas on why this is happening?


回答1:


The various Big...Style builders create their own 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.




回答2:


When you add your custom bigContentView it will replace the contentview that is created by Notification.BigPictureStyle, Notification.BigTextStyle or 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.

You could find a tutorial of how to do this here.



来源:https://stackoverflow.com/questions/12247153/in-android-on-jb-how-can-i-add-an-action-to-a-custom-rich-notification

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!