从兼容性 Fragment 添加/更改兼容性 SimpleMenu/MenuItem
我意识到这是一个特定的问题,但我觉得其他处理兼容性的人一定已经处理过这个问题。
当用户在 ViewPager 中的各个片段中滑动时,我还希望 actionBar 菜单项发生变化。我不确定这对于 兼容性操作栏是否可以轻松实现,任何指示或帮助将不胜感激。我只是通过 setTitle() 更改标题,因为 ActionBarHelper 处理了这个问题,但是我找不到任何用于更新菜单项的内容。我尝试了以下操作,但失败了。
public void setMenuDynamically(int resId){
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(resId, menu);
}
查看代码,似乎应该有一种简单/明显的方法来获取 SimpleMenu 的句柄并添加项目并设置其图标。
提前致谢(我希望谷歌男孩们能按照 Android 开发者 Google+ 的建议阅读这篇文章)
I realise this is a specific problem however I feel like others who are dealing with compatibility must have dealt with this.
As the user swipes through various fragments in the ViewPager I would also like the actionBar menu items to change. I am not sure if this is easily doable for the compatibility actionbar, any direction or help would be extremely appreciated. I am changing the title simply via setTitle() since the ActionBarHelper handles this however i cant find anything for updating the menu items. I tried the following but it fails..
public void setMenuDynamically(int resId){
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(resId, menu);
}
Looking through the code it seems there should be an easy/obvious way to get a handle to the SimpleMenu and add an item and set its icon.
Thanks in advance ( I am hoping the google boys are reading this as the android developers Google+ suggests)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,如果我描述的事情很糟糕,或者只是对这个主题没有太多了解,请告诉我。如果是第一个我真的很抱歉。不管怎样,我似乎让它发挥作用,但不确定这是否是正确的方法。
AcitonBarHelper
ActionBarHelperBase (适用于 2.2 - 3.0 设备)
并为 honeycomb 和 ICS 创建类似的方法,
最后我有一个用于页面更改的侦听器,并且在该侦听器中我调用...
我不确定 MenuItemCompat 是否是必要的,但我仍然包含了它。至少对于 2.2 来说一切似乎都工作得很好。我很可能必须在覆盖中进行更改,但我可以从这里处理自己。
Ok well please let me know if I suck as describing things or if there just is not much knowledge on this topic. If the first I am really sorry guys. Regardless I seemed to get this to work but am unsure if this is the correct way.
AcitonBarHelper
ActionBarHelperBase (for 2.2 - 3.0 devices )
And create similar methods for honeycomb and ICS
finally i have a listener for page changing and in that listener i call...
I am not sure if the MenuItemCompat is necessary but I included it nonetheless. Everything seems to work great for 2.2 at least. I will most likely have to make changes in the Overrides but I can handle myself from here.