I understand you want to have different menus for each fragment? You can specify a menu for each fragment and it will only show when that fragment is attached to the Activity. The code below all belongs in a fragment.
You must tell the fragment it has an options menu:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
}
Then inflate the the menu for this fragment:
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.about, menu);
}
Then handle each item in the menu when it is clicked:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle menu item click here
return super.onOptionsItemSelected(item);
}
You can also specify a "global" menu in the activity and those menu item will be shown as well as the menu items for the current fragment.