I have a fragment where I try to change the title of the actionbar. This worked until i added setHasOptionsMenu(true) to the fragment.
How can i solve this? Because I need the optionsmenu in the fragment.
In fragment
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
((MainActivity)getActivity()).setActionBarTitle(getString(R.string.title_view_tree));
setHasOptionsMenu(true);
return inflater.inflate(R.layout.fragment_view_tree, container, false);
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.menu_view_tree,menu);
super.onCreateOptionsMenu(menu,inflater);
}
In MainActivity:
public void setActionBarTitle(String title) {
getSupportActionBar().setTitle(title);
}
When I disable setHasOptionsMenu(true) by using // then the title of the actionbar changes correctly.