Reputation: 969
I am trying to set CollapseMode of the new CollapsingToolbarLayout
I can create new params for the child and can assign it. But this does not change the layout_scrollFlags I think i need to edit.
CollapsingToolbarLayout.LayoutParams mParams = new CollapsingToolbarLayout.LayoutParams(mCollapsing.getLayoutParams());
mParams.setCollapseMode(CollapsingToolbarLayout.LayoutParams.COLLAPSE_MODE_OFF);
mCollapsing.getChildAt(0).setLayoutParams(mParams);
So I would like to turn on and off the scroll mode.
Has anyone done this yet?
Upvotes: 1
Views: 1414
Reputation: 969
After a few hours of playing with this.
Turns out that the layout_scrollFlags is a layoutparams in AppBarLayout class.
You can get the current flags using
AppBarLayout.LayoutParams mParams = (AppBarLayout.LayoutParams) abBar.getChildAt(0).getLayoutParams();
int currentScrollFlags = mParams.getScrollFlags();
This means you can turn it off by using
mParams.setScrollFlags(0);
Some may ask why, I need my user to make a selection in the view bellow, once this has happened i will turn the flag to 3, which is scroll|exitUntilCollapsed You can also use
AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS
AppBarLayout.LayoutParams.SCROLL_FLAG_EXIT_UNTIL_COLLAPSED
AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS
AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS_COLLAPSED
Hope this helps someone.
Upvotes: 4