How to set app:layout_scrollFlags for Toolbar programmatically

I’d strongly recommend against changing the scrolling flags based on what tab is selected – having the Toolbar automatically return (and the content move down) when scrolling to a non-recyclerview tab can be very jarring and probably not an interaction pattern you want (exasperated if your two RecyclerView tabs are next to one another).

However, if you want to see it in person, you can use setScrollFlags() to set the scroll flags programmatically:

Toolbar toolbar = ... // your toolbar within an AppBarLayout
AppBarLayout.LayoutParams params = 
    (AppBarLayout.LayoutParams) toolbar.getLayoutParams();
params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL
    | AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS);

In order to clear flags

params.setScrollFlags(0)

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)