Hide/Show Toolbar programmatically on CoordinatorLayout

前端 未结 3 1997
盖世英雄少女心
盖世英雄少女心 2020-12-23 13:24

When I scroll my RecycleView ToolBar hide or show (with animation).

How I can return ToolBar back programmatically?

3条回答
  •  天命终不由人
    2020-12-23 14:21

    My problem was very similar to @Artem I tried many fix but none of them worked for me. @Jraco11's answer is correct when you use AppBarLayout. @johnrao07 not worked for me. But I found a perfect solution for this problem when we use Toolbar.

    To hide Toolbar programatically

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

    To show Toolbar programatically

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

    Refer original answer(answer by @Android HHT):- programmatically-show-toolbar-after-hidden-by-scrolling-android-design-library

提交回复
热议问题