Managing Action Bar titles when using fragments and the backstack

社会主义新天地 提交于 2019-12-12 15:40:59

问题


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

• effectively manage action bar titles when using fragments on a backstack?


回答1:


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:

Fragments onResume from back stack



来源:https://stackoverflow.com/questions/23811136/managing-action-bar-titles-when-using-fragments-and-the-backstack

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!