We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Makes sense to add a scrolling behavior to the BottomNavigationBar for better visibility
BottomNavigationBar
Here's the link to the article: https://android.jlelse.eu/scroll-your-bottom-navigation-view-away-with-10-lines-of-code-346f1ed40e9e?__s=ep727fgnkqv7dsftb1ut
Copy The code into project
The code
Set the behavior to the HomeActivity's BottomNavigationBar
HomeActivity
class BottomNavigationBehavior<V : View>(context: Context, attrs: AttributeSet) : CoordinatorLayout.Behavior<V>(context, attrs) { override fun onStartNestedScroll(coordinatorLayout: CoordinatorLayout, child: V, directTargetChild: View, target: View, axes: Int, type: Int): Boolean { return axes == ViewCompat.SCROLL_AXIS_VERTICAL } override fun onNestedPreScroll(coordinatorLayout: CoordinatorLayout, child: V, target: View, dx: Int, dy: Int, consumed: IntArray, type: Int) { super.onNestedPreScroll(coordinatorLayout, child, target, dx, dy, consumed, type) child.translationY = max(0f, min(child.height.toFloat(), child.translationY + dy)) } 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 } } }
And on the BottomNavigationView XML add this attribute
BottomNavigationView
app:layout_behavior="com.joaquimley.transporteta.<_SOME_PACKAGE_>.BottomNavigationBehavior"
The text was updated successfully, but these errors were encountered:
This might not be needed with the release of 28-alpha
28-alpha
Sorry, something went wrong.
No branches or pull requests
Makes sense to add a scrolling behavior to the
BottomNavigationBar
for better visibilityHere's the link to the article: https://android.jlelse.eu/scroll-your-bottom-navigation-view-away-with-10-lines-of-code-346f1ed40e9e?__s=ep727fgnkqv7dsftb1ut
Tasks ⚙
Copy
The code
into projectSet the behavior to the
HomeActivity
'sBottomNavigationBar
The code
And on the
BottomNavigationView
XML add this attributeapp:layout_behavior="com.joaquimley.transporteta.<_SOME_PACKAGE_>.BottomNavigationBehavior"
The text was updated successfully, but these errors were encountered: