How to implement Custom Collapsable Toolbar in android?
The AppBarComponent
provides a method called .setExpanded(boolean expanded)
, which allows you to expand your AppBarComponent
.
But keep in mind, that this method relies on this layout being a direct child of a CoordinatorLayout
.
You can read this for more information.
If you want to animate to a custom offset, try using the setTopAndBottomOffset(int)
method.
CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) appBar.getLayoutParams();final AppBarLayout.Behavior behavior = (AppBarLayout.Behavior) params.getBehavior();if (behavior != null) { ValueAnimator valueAnimator = ValueAnimator.ofInt(); valueAnimator.setInterpolator(new DecelerateInterpolator()); valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { behavior.setTopAndBottomOffset((Integer) animation.getAnimatedValue()); appBar.requestLayout(); } }); valueAnimator.setIntValues(0, -900); valueAnimator.setDuration(400); valueAnimator.start();}