In order to enable/disable the scroll of the collapsing toolbar you can provide a custom DragCallback as part of your AppBarLayout's behavior. Here is a sample code:
private void setAppBarDragging(final boolean newValue) {
AppBarLayout appBarLayout = (AppBarLayout) findViewById(R.id.appbar_layout);
CoordinatorLayout.LayoutParams params =
(CoordinatorLayout.LayoutParams) appBarLayout.getLayoutParams();
AppBarLayout.Behavior behavior = new AppBarLayout.Behavior();
behavior.setDragCallback(new AppBarLayout.Behavior.DragCallback() {
@Override
public boolean canDrag(AppBarLayout appBarLayout) {
return newValue;
}
});
params.setBehavior(behavior);
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…