Programmatically show Toolbar after hidden by scrolling (Android Design Library)

前端 未结 3 702
遥遥无期
遥遥无期 2021-01-04 08:02

I have the following layout: a drawer, with the main content view having a AppBarLayout, RecyclerView and a TextView. When I scroll the recycler, the toolbar is correctly hi

3条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-04 08:15

    You can do it by accessing to the AppBarLayout that contains your Toolbar

    Here is an example:

    if (mToolbar.getParent() instanceof AppBarLayout){
      ((AppBarLayout)mToolbar.getParent()).setExpanded(true,true);
    }
    

    setExpanded(expand,animation) will do the work. You can also have a a reference to the AppBarLayout instead of call the getParent from the toolbar.

提交回复
热议问题