Changing Toolbar and CollapsingToolbarLayout scroll flags programmatically
I found it working
public void disableToolBarScrolling() {
CollapsingToolbarLayout toolbar = findViewById(R.id.collap_toolbar);
AppBarLayout.LayoutParams params = (AppBarLayout.LayoutParams) toolbar.getLayoutParams();
params.setScrollFlags(0);
}
public void enableToolBarScrolling() {
CollapsingToolbarLayout toolbar = findViewById(R.id.collap_toolbar);
AppBarLayout.LayoutParams params = (AppBarLayout.LayoutParams) toolbar.getLayoutParams();
params.setScrollFlags(SCROLL_FLAG_SCROLL | SCROLL_FLAG_ENTER_ALWAYS);
}
Yes. Let's say you are going from the CollapsingToolbarLayout fragment to the Toolbar one.
You collapse your
AppBarLayout
usingAppBarLayout.setExpanded(false)
;You change the scroll flags to fit your needs.
AppBarLayout.LayoutParams p = (AppBarLayout.LayoutParams) toolbar.getLayoutParams(); p.setScrollFlags(...); toolbar.setLayoutParams(p);
Same goes for the CollapsingToolbarLayout if necessary. I guess it should be something like:
collapsingToolbarParams.setScrollFlags(0); //no flags for ctl toolbarParams.setScrollFlags(SCROLL_FLAG_SCROLL | SCROLL_FLAG_ENTER_ALWAYS); //new flags for toolbar