Created
March 3, 2020 03:27
-
-
Save VibeMage/2a6ec8cf1c8bb928518d2e96f5ad55e7 to your computer and use it in GitHub Desktop.
[disable/re-enable the expansion CoordinatorLayout behavior]#Android
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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