Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change layout_scrollFlags programmatically in CollapsingToolbarLayout

I have the following CollapsingToolbarLayout tag in my xml:

<android.support.design.widget.CollapsingToolbarLayout
    android:id="@+id/collapsingToolbarLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:contentScrim="?attr/colorPrimary"
    app:expandedTitleMarginStart="@dimen/expanded_toolbar_title_margin_start"
    app:layout_scrollFlags="exitUntilCollapsed">

I would like to change the scrollFlags value programmatically (run time) - specifically, toggle the scrollable flag. Is it possible?

like image 738
Ohad Avatar asked Sep 04 '15 23:09

Ohad


1 Answers

CollapsingToolbarLayout collapsingToolbar = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
AppBarLayout.LayoutParams params = (AppBarLayout.LayoutParams) collapsingToolbar.getLayoutParams();
params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SNAP); // list other flags here by |
collapsingToolbar.setLayoutParams(params);

One thing worth mentioning - setScrollFlags overrides all previous flags so we should be careful not to lose already existing flag

like image 160
DmitryArc Avatar answered Nov 20 '22 17:11

DmitryArc