Home » Android » android – ActionBar Menu Items disappear in NestedFragments

android – ActionBar Menu Items disappear in NestedFragments

Posted by: admin May 14, 2020 Leave a comment


Since android 4.2 now support NestedFragment , and added it to support v13.

I use this NestedFragment on a classic situation : Create fragmentA that can swipe left and right and consume a majority of the screen space, and insert fragmentB and fragmentC into each fragment page.

My Problem is the MenuItem I create in fragmentB and fragmentC can`t show on Activity`s actionbar.Which before I use NestedFragment , it works well.

How to&Answers:

got at some point the same problem. If you’re using the ActionBarSherlock library this is a small bug. What you basically have to do is to call from your parent fragment from the onCreateOptionsMenu() method the onCreateOptionsMenu() method of the children, something like:

public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    getChildFragment().onCreateOptionsMenu(menu, inflater);

hope this works, let me know.