Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using AppBarLayout.Behavior.DragCallback to control scroll of collapsing toolbar layout

I want to be able to enable and disable the scroll of collapsing toolbar. Can anyone show me an example how to use AppBarLayout.Behavior.DragCallback?

https://developer.android.com/reference/android/support/design/widget/AppBarLayout.Behavior.DragCallback.html

like image 551
syloc Avatar asked Oct 18 '15 00:10

syloc


1 Answers

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);
}
like image 112
dev.bmax Avatar answered Nov 15 '22 15:11

dev.bmax