Hide/Show Toolbar programmatically on CoordinatorLayout

前端 未结 3 2001
盖世英雄少女心
盖世英雄少女心 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:11

    Is that what you looking for?

    Toolbar toolbar = findViewById(R.id.toolbar);  // or however you need to do it for your code
    AppBarLayout.LayoutParams params = (AppBarLayout.LayoutParams) toolbar.getLayoutParams();
    params.setScrollFlags(0);  // clear all scroll flags
    

    link: How to enable/disable toolbar scrolling programmatically when using design support library

    In order to hide the Toolbar your can just do something like this:

    toolbar.animate().translationY(-toolbar.getBottom()).setInterpolator(new AccelerateInterpolator()).start();
    

    If you want to show it again you call:

    toolbar.animate().translationY(0).setInterpolator(new DecelerateInterpolator()).start();
    

提交回复
热议问题