[英]Actionbar: inflate new menu resource
I have an ActionBar
in my app with tabs. 我的应用程序中有一个带有选项卡的
ActionBar
。 Each tab has its own Fragment
. 每个选项卡都有其自己的
Fragment
。
In a Fragment
class, onCreateOptionsMenu
gets called, but just once. 在
Fragment
类中,仅调用一次onCreateOptionsMenu
。 Based on user input, I'd like to inflate a new menu resource, after the first time the onCreateOptionsMenu
is called. 根据用户的输入,在第一次调用
onCreateOptionsMenu
之后 ,我想添加一个新的菜单资源。
How would I do this? 我该怎么做?
You should be able to dynamically change the ActionBar menu. 您应该能够动态更改ActionBar菜单。 Using if statements etc in the
onCreateOptionsMenu
. 在
onCreateOptionsMenu
使用if语句等。
When you need to re-run the logic call 当您需要重新运行逻辑调用时
invalidateOptionsMenu();
Which will recreate the menu items. 将重新创建菜单项。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.