Skip to content

Instantly share code, notes, and snippets.

@dzolnai
Created December 28, 2020 15:20
Show Gist options
  • Save dzolnai/23ee84e3dca76f4f9d2a013a666ba719 to your computer and use it in GitHub Desktop.
Save dzolnai/23ee84e3dca76f4f9d2a013a666ba719 to your computer and use it in GitHub Desktop.
Disallow the toolbar expand on a collapsible toolbar layout
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