所以我有一个名为“container”的片段容器,它是一个FrameLayout。
在这个容器中,我放置了一个名为CollectionsFragment的ViewPager片段。
CollectionsFragment有3个片段:
AllCollectionsFragment包含一个集合列表和一个操作栏中的微调器菜单,当用户点击一个集合时,另一个名为ViewCollectionFragment的片段被放置在activity容器中,所以:
AllCollectionsFragment - > onClick(位置) - > ViewCollectionFragment(放置在主活动容器中)
问题是ViewCollectionFragment没有菜单。它有setHasOptionsMenu(false)。但是,即使显示ViewCollectionFragment,Android仍然会调用AllCollectionsFragment onCreateOptionsMenu,并且当ViewCollectionFragment可见时,AllCollectionsFragment的菜单仍然显示。
我正在使用FragmentStatePagerAdapter,我将CollectionsFragment的getChildFragmentManager()传递给适配器。
我还有一个活动容器的onBackstackChangeListener,当backstack改变时,它会使选项菜单无效: CollectionsFragment - > AllCollectionsFragment(默认) - >选择集合 - >在Backstack和主容器中添加ViewCollectionsFragment-> invalidateOptionsMenu - >仍然调用AllCollectionsFragment.onCreateOptionsMenu并显示菜单
任何想法为什么或我应该给出更多解释?
答案 0 :(得分:0)
我为这个"问题"做了一个解决方法。我在我的主要活动中隐藏菜单(我检查片段是否在其标签处)并且我检查片段是否背板是> 0并隐藏菜单......