Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
471 views
in Technique[技术] by (71.8m points)

java - 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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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);
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...