Reputation: 863
I have two fragments, one is for folder and other is for photos in Tab layout. Photos fragment have many photos when I select one item(picture) I want to change the toolbar entirely like
below
how i will do this and have to listen clicks events on toolbar?
Upvotes: 2
Views: 14136
Reputation: 1023
If you want to change your toolbar from a fragment, the code below may help you.
Add toolbar in your fragment XML and then you can change the toolbar of your activity like this:
Toolbar toolbar = view.findViewById(R.id.toolbar);
((MainActivity) getActivity()).getSupportActionBar().hide();
((MainActivity) getActivity()).setSupportActionBar(toolbar);
Upvotes: 2
Reputation: 766
Read Documentation click here.
Upvotes: 2
Reputation: 1224
just put it in your fragment get your Actvity
toolbar with id
and set toolbar as u desired in your fragment
Toolbar toolbar = (Toolbar) getActivity().findViewById(R.id.toolbar);
toolbar.setTitle("title");
Upvotes: 7