问题描述
我的应用程序有一个使用了FragmentManager来push和pop片段到backstack的活动。然而,当backstack有2个片段和最后一个片段被弹出,我也不怎么检测到这种适当设置操作栏的标题。我希望有一个片段,我可以重写,以确定当它成为可见的一些方法,但这些都不建议如uservisiblehint,onHiddenChanged等被调用。我怎样才能既:
My app has an activity which uses the FragmentManager to push and pop fragments onto the backstack. However, when the backstack has 2 fragments and the last fragment is popped, I do not how to detect this to set the title of the Action Bar appropriately. I was hoping there was some method on a fragment I could override to determine when it becomes visible, but none of those suggested e.g. uservisiblehint, onHiddenChanged, etc. are called. How can I either:
•确定何时片段变得可见;或
• determine when a fragment becomes visible; OR
•在backstack使用片段时,有效地管理操作栏标题?
• effectively manage action bar titles when using fragments on a backstack?
推荐答案
您可以添加 addOnBackStackChangedListener
将被调用每次回栈变化。在这个函数中,你可以简单地得到最顶层的片段,并调用 onResume
吧。
You can add a addOnBackStackChangedListener
which will get called every time back stack changes. Inside this function you can simply get the topmost fragment and call onResume
for it.
有关详细信息,您可以参考以下链接:
For more information you can refer to following link:
这篇关于使用片段和backstack在管理操作栏冠军的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!