Java – use appbarlayout Behavior. Dragcallback to control the scrolling of the collapsed toolbar layout

I want to be able to enable and disable scrolling on the collapse toolbar Who can tell me how to use appbarlayout Behavior. Dragcallback example?

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

Solution

To enable / disable scrolling of the collapse toolbar, you can provide a custom dragcallback as part of the appbarlayout behavior This is an example 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);
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>