Why my Android ActionBar doesn't update when it is explictily changed

醉酒当歌 提交于 2019-12-17 14:29:08

问题


I've seen questions on SO that related to these many times. So I've decided to post the reason why it happens and also the solution so that many SO users will get the benefit of the answer.

For sometime now I've seen a reoccurring issue where I would change the ActionBar title and it would get ellipsized shorter than it should. Another symptom of this is having your title wrap when it shouldn't or just stay completely blank. When you change the the action bar buttons it wouldn't update correctly and I would be left with either no action bar buttons even though they have definitely been added or double up on existing action bar buttons.

It turns' out this is a relatively straight forward issue. It mainly happens when you use a ViewPager with the getChildFragmentManager() to manage your fragments.


回答1:


The fragment that hosts the ViewPager and the child Fragments that are created by your adapter must also call setHasOptionsMenu(true); in their onCreate() method's, so that all of the option menu events get passed down to the child fragments and on to their children and so on.

Simple really, when you think about it. But its just one of those things.

Hope this helps and I welcome your comments, Simon



来源:https://stackoverflow.com/questions/24089136/why-my-android-actionbar-doesnt-update-when-it-is-explictily-changed

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