How to reset the Toolbar position controlled by the CoordinatorLayout?

后端 未结 8 1705
情话喂你
情话喂你 2020-12-04 16:19

The app I\'m working on consists of a Navigation Drawer which is implemented in an Activity. The activity layout is as follows:



        
相关标签:
8条回答
  • 2020-12-04 17:15

    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 
    
    0 讨论(0)
  • 2020-12-04 17:20

    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.

    0 讨论(0)
提交回复
热议问题