Android 多选项菜单
我想在 Android 中有两个选项菜单,使用活动内的按钮触发。这可能吗?如果是这样,我将如何去做呢?
I would like to have two options menus in Android that are triggered using buttons inside the activity. Is this possible? If so, how would I go about doing so?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定是否有直接的方法可以做到这一点,但有一种解决方法。您可以通过声明
public boolean onCreateOptionsMenu(Menu menu)
和/或public boolean onPrepareOptionsMenu(Menu menu)
来创建以常规方式启动菜单的方法,但有两个不同的方法“模式”。从按钮中,您只需调用openOptionsMenu()
,即可以编程方式打开选项菜单。在打开菜单之前,只需将“模式”设置为按钮菜单应有的状态即可。我希望您明白我的意思,如果您需要澄清,请告诉我!I'm not sure if there's a direct way of doing this, but there is kind of a work around. You could create the method that launches the menu the regular way, by declaring
public boolean onCreateOptionsMenu(Menu menu)
and/orpublic boolean onPrepareOptionsMenu(Menu menu)
but have two different "modes". From your button, you can programmatically open the options menu by simply callingopenOptionsMenu()
. Just before you open the menu, just set the "mode" to whatever the button's menu should be in. I hope you understand what I mean, let me know if you need clarifying!