Well, his workaround is bigger, and it might be better to configure OnPageChangeListener , but it works for me. The challenge is to determine if the current fragment is visible at creation. You can use this menu for this. In your snippet:
@Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setHasOptionsMenu(true);
and this one
@Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { ... if(isMenuVisible()) { // menu should be visible if current fragment is visible right now setUserVisibleHint(true); // manually set value to true } ... return view;
Maybe someone will find this helpful. This works for me.
kara4k Jun 12 '17 at 14:30 2017-06-12 14:30
source share