Skip to content

Instantly share code, notes, and snippets.

@VibeMage
Created March 3, 2020 03:27
Show Gist options
  • Select an option

  • Save VibeMage/2a6ec8cf1c8bb928518d2e96f5ad55e7 to your computer and use it in GitHub Desktop.

Select an option

Save VibeMage/2a6ec8cf1c8bb928518d2e96f5ad55e7 to your computer and use it in GitHub Desktop.
[disable/re-enable the expansion CoordinatorLayout behavior]#Android
public class DisableableAppBarLayoutBehavior extends AppBarLayout.Behavior {
private boolean mEnabled;
public DisableableAppBarLayoutBehavior() {
super();
}
public DisableableAppBarLayoutBehavior(Context context, AttributeSet attrs) {
super(context, attrs);
}
public void setEnabled(boolean enabled) {
mEnabled = enabled;
}
@Override
public boolean onStartNestedScroll(CoordinatorLayout parent, AppBarLayout child, View directTargetChild, View target, int nestedScrollAxes) {
return mEnabled && super.onStartNestedScroll(parent, child, directTargetChild, target, nestedScrollAxes);
}
public boolean isEnabled() {
return mEnabled;
}
}
AppBarLayout myAppBar = ....;
CoordinatorLayout.LayoutParams layoutParams = (CoordinatorLayout.LayoutParams) myAppBar.getLayoutParams();
((DisableableAppBarLayoutBehavior) layoutParams.getBehavior()).setEnabled(false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment