I need to implement such a structure. Sliding panel, clicking on a variant from the list, a fragment is loaded into the main activity instead of FrameLayout. At this stage, I had no problems, but most importantly, in each fragment I should have my own toolbar, I’m not talking about the action menu, I know how to change it, I’m talking about the whole toolbar, for example, somewhere there should be a search in it, somewhere a drop-down list and so on, as in VK
1 answer
Good day. I have this opportunity implemented in the activit itself, in which fragments are placed.
SomeFragment.java (This is a fragment class)
@Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) { super.onCreate(savedInstanceState); rootView = inflater.inflate(R.layout.auth_fragment, container, false); IMainActivity iMainActivity = (MainActivity) getActivity(); iMainActivity.changeToolbarTitle(R.string.title_activity_auth); I get the activation from the fragment and call in it a method that changes the toolbar according to my desire.
(I have an activit markup .xml file that includes (<include />) a different markup file, which, in turn, includes a toolbar. Thus, activating can directly modify the toolbar
MainActivity.java
public void onCreate(){ // smth before toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); //smth after } // some methods, etc... public void changeToolbarTitle(int resId) { toolbar.setTitle(resId); } |