Android的 - NestedFragments参加填充选项菜单 [英] Android - NestedFragments participate in populating the options menu

查看:166
本文介绍了Android的 - NestedFragments参加填充选项菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实现了新的嵌套片段的功能,不得不跌入一个问题。
我的看法是基本上是这样的:
主要活动( A ),其中包括一个片段(),这个片段()包括有各3页寻呼机适配器他们是( C )也是一个片段。
previously新getchildfragmentmanger这不是可行的,但它完美。
但一个问题也出现,我想碎片C到能够参加填充选项菜单。
我累了把setHasOptionsMenu(真)在onActivityCreated方法上的每个我的 C 片段和压倒一切也onCreateOptionsMenu但没有任何反应...
如果我尝试从填充碎片菜单中的(这是寻呼机适配器的容器),我可以改变菜单项...

i am implementing the new nested fragment feature and had stumble into a problem. my view is basically this: a main activity(A) that includes a fragment(B), this fragment(B) includes a pager adapter that has 3 pages each of them is a fragment(C) also. previously to the new getchildfragmentmanger this was not doable, but it works perfectly. but one issue did arise, i want fragments C to be able to participate in populating the option menu. i tired putting setHasOptionsMenu(true) in the onActivityCreated method on each of my C fragments and overriding also onCreateOptionsMenu but nothing happens... if i try to populate the menu from fragment B (which is the container of the pager adapter) i can change the menu items...

什么想法?

感谢。

推荐答案

是的,他们可以。

在Android 4.2或支持库revisiion 11嵌套的片段参与填充选项菜单,永诺需要调用 setHasOptionsMenu(真)的onCreate ()

With android 4.2 or support library revisiion 11 nested fragments participate in populating options menu, as allways you need to call setHasOptionsMenu(true) during onCreate().

但是,如果您使用的是ActionBarSherlock他们不会,你必须手动将来自父系的片段叫 onCreateOptionsMenu()嵌套片段的方法 onCreateOptionsMenu()

But if you are using ActionBarSherlock they won't, you have to manually call from parent fragment onCreateOptionsMenu() nested fragment method onCreateOptionsMenu().

更新问题

这篇关于Android的 - NestedFragments参加填充选项菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆