Oncreateoptionsmenu Is Not Called After A Fragment Add & Remove
I have a fragment where I can call ActivityCompat.invalidateOptionsMenu(getActivity()); and the method onCreateOptionsMenu() is successfully called on both: Activity and Fragment.
Solution 1:
Please try below code :
@Override
public boolean onCreateOptionsMenu(Menu menu) {
Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.fragment_home);
if (fragment != null) {
fragment.onCreateOptionsMenu(menu, getMenuInflater());
return true;
}
getMenuInflater().inflate(R.menu.menu_layout, menu);
return super.onCreateOptionsMenu(menu);
}
Post a Comment for "Oncreateoptionsmenu Is Not Called After A Fragment Add & Remove"