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?
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?
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");
}
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);