How to reset the Toolbar position controlled by the CoordinatorLayout?

后端 未结 8 1785
情话喂你
情话喂你 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 
    

提交回复
热议问题