-1

I have an option menu in an activity.

I want to access that menu in a Fragment and I want set title for that.

How can I access this?

Can anyone please help me?

Ian
  • 30,182
  • 19
  • 69
  • 107
ananya
  • 1,001
  • 6
  • 33
  • 50

2 Answers2

1

when overriding the optionsmenu in a fragment a menu reference is passed, this goes through activity's onCreateOptionsMenu first, so you can find and modify the menuItems.

@Override
    public void onPrepareOptionsMenu(Menu menu){
          menu.findItem(R.id.shouldModifyinFragment).setTitle("newTitle");
}
Ramin
  • 474
  • 6
  • 22
0

the easy way to do this ...... first of all build actionBar in your activity look at the DOC.! then change the title like below!

In your Activity:

public void setActionBarTitle(String title){
YOUR_CUSTOM_ACTION_BAR_TITLE.setText(title);
}

In your Fragment:

((yourActivity) getActivity()).setActionBarTitle(YOUR_TITLE);
Nowshad
  • 294
  • 1
  • 14