private void handleToolbarVisibility(final boolean show) { final AppBarLayout appBarLayout = (AppBarLayout) mToolbar.getParent(); final CoordinatorLayout rootLayout = (CoordinatorLayout) appBarLayout.getParent(); final CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) appBarLayout.getLayoutParams(); final AppBarLayout.Behavior behavior = (AppBarLayout.Behavior) params.getBehavior(); if (show) { // Show appBar behavior.setTopAndBottomOffset(0); behavior.onNestedPreScroll(rootLayout, appBarLayout, null, 0, 1, new int[2]); } else { // Hide appBar behavior.onNestedFling(rootLayout, appBarLayout, null, 0, 10000, true); } }
private MaterialViewPagerHeader(Toolbar toolbar) { this.toolbar = toolbar; this.context = toolbar.getContext(); this.toolbarLayout = (View) toolbar.getParent(); }