Created
December 28, 2020 15:20
-
-
Save dzolnai/23ee84e3dca76f4f9d2a013a666ba719 to your computer and use it in GitHub Desktop.
Disallow the toolbar expand on a collapsible toolbar layout
This file contains 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
internal fun disallowToolbarExpand() { | |
// Taken from: https://stackoverflow.com/a/49218710/1395437 | |
binding.appBar.setExpanded(false, false) | |
ViewCompat.setNestedScrollingEnabled(binding.content, false) | |
val params = binding.appBar.layoutParams as CoordinatorLayout.LayoutParams | |
if (params.behavior == null) { | |
params.behavior = AppBarLayout.Behavior() | |
} | |
val behaviour = params.behavior as AppBarLayout.Behavior | |
behaviour.setDragCallback(object : AppBarLayout.Behavior.DragCallback() { | |
override fun canDrag(appBarLayout: AppBarLayout): Boolean { | |
return false | |
} | |
}) | |
binding.chevron.isVisible = false | |
binding.clickableLayout.isVisible = false | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment