How to enable/disable toolbar scrolling programmatically when using design support library
The Toolbar
, being a child of the AppBarLayout
, gets its LayoutParams
from the AppBarLayout
. These layout params have the scroll flags that are set in the XML.
So, you get the AppBarLayout.LayoutParams
from the Toolbar
, and call
setScrollFlags()
to change the flags to the value you want.
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(AppBarLayout.LayoutParams.SCROLL_FLAG_NO_SCROLL); // clear all scroll flags
Remove app:layout_scrollFlags="scroll|enterAlways"
wherever you want to disable taskbar scrolling.