Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to lock expanding/collapsing action programmatically?

I would like to keep this layout on specific action:

Initial layout

Nowadays, I can collapse or expand this CoordinatorLayout by performing swipe on it. I want to block this behavior.

like image 374
piotrek1543 Avatar asked Nov 29 '22 09:11

piotrek1543


1 Answers

I assume your list is using a RecyclerView.

You can turn off nested scrolling on your RecyclerView which will disable the toolbar collapse:

recyclerView.setNestedScrollingEnabled(false);

You can lock the toolbar by clearing the scroll flags:

CollapsingToolbarLayout toolbar = findViewById(R.id.collapsingToolbar);  // or however you need to do it for your code
AppBarLayout.LayoutParams params = (AppBarLayout.LayoutParams) toolbar.getLayoutParams();
params.setScrollFlags(0);  // clear all scroll flags
like image 120
kris larson Avatar answered Dec 05 '22 04:12

kris larson