I have an activity with navigation drawer which replace the main_fragment_container on the activity. When one of the fragments is displayed I want to change the layout of the to
Not sure what you are trying to accomplish but I think, if possible, you should approach this by letting the fragments customize your toolbar rather than replacing it. Your can let your fragments hide/show views on the toolbar depending on your needs.
Add setHasOptionsMenu(true);
in the fragments OnCreateView()
and then override onOptionsMenuCreated()
Like this:
@Override
public View onCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
setHasOptionsMenu(true);
return inflater.inflate(R.layout.result_list, container, false);
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.this_frag_menu, menu);
super.onCreateOptionsMenu(menu, inflater);
}
If you need to do more specific things with the toolbar you can get the instance using
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);