The app I\'m working on consists of a Navigation Drawer which is implemented in an Activity. The activity layout is as follows:
As document said
AppBarLayout supports
void setExpanded (boolean expanded, boolean animate);
Sets whether this AppBarLayout is expanded or not.
- expanded boolean: true if the layout should be fully expanded, false if it should be fully collapsed
- animate boolean: Whether to animate to the new state
So first, you need
AppBarLayout appBarLayout = findViewById(R.id.appBarLayout);
then to expand layout
appBarLayout.setExpanded(true, true); // with animation
appBarLayout.setExpanded(true, false); // without animation
and to collapse layout
appBarLayout.setExpanded(false, true); // with animation
appBarLayout.setExpanded(false, false); // without animation
First get a AppBarLayout refrence in you MainActivity, then in the pause state of the fragment that is being replaced, use the method below to expand toolbar :
MainActivity.appbar.setExpanded(true,true);
And or to close the toolbar :
MainActivity.appbar.setExpanded(false,true);
The second parameter is used to scroll the toolbar smoothly.