Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ValCanBuild/89d2720dbd21d664beefa5eeb433c4b3 to your computer and use it in GitHub Desktop.
Save ValCanBuild/89d2720dbd21d664beefa5eeb433c4b3 to your computer and use it in GitHub Desktop.
class BottomNavigationBehavior<V : View>(context: Context, attrs: AttributeSet) :
CoordinatorLayout.Behavior<V>(context, attrs) {
// Rest of the code is the same
override fun layoutDependsOn(parent: CoordinatorLayout?, child: V, dependency: View?): Boolean {
if (dependency is Snackbar.SnackbarLayout) {
updateSnackbar(child, dependency)
}
return super.layoutDependsOn(parent, child, dependency)
}
private fun updateSnackbar(child: View, snackbarLayout: Snackbar.SnackbarLayout) {
if (snackbarLayout.layoutParams is CoordinatorLayout.LayoutParams) {
val params = snackbarLayout.layoutParams as CoordinatorLayout.LayoutParams
params.anchorId = child.id
params.anchorGravity = Gravity.TOP
params.gravity = Gravity.TOP
snackbarLayout.layoutParams = params
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment