<androidx.coordinatorlayout.widget.CoordinatorLayout
android:fitsSystemWindows="false"
...>
<com.google.android.material.bottomnavigation.BottomNavigationView
... />
Fixed code in kotlin...
/**
* A wrapper around [ViewCompat.setOnApplyWindowInsetsListener] which stores the initial view state, and provides them whenever a
* [android.view.WindowInsets] instance is dispatched to the listener provided.
*
*
* This allows the listener to be able to append inset values to any existing view state
* properties, rather than overwriting them.
*/
fun setOnApplyInsetsListener(view: View, listener: OnApplyInsetsListener) {
val tagState = view.getTag(R.id.insetter_initial_state) as ViewState?
val initialState: ViewState
if (tagState != null) {
initialState = tagState
} else {
initialState = ViewState(view)
view.setTag(R.id.insetter_initial_state, initialState)
}
if (ViewCompat.isAttachedToWindow(view)) {
registerForWindowInsets(view, getMostParentView(view), initialState, listener)
} else {
view.addOnAttachStateChangeListener(
object : View.OnAttachStateChangeListener {
override fun onViewAttachedToWindow(v: View) {
v.removeOnAttachStateChangeListener(this)
registerForWindowInsets(v, getMostParentView(v), initialState, listener)
}
override fun onViewDetachedFromWindow(v: View) {
// no-op
}
})
}
}
/**
* Register for window insets.
* Commits result through wrapper.
*/
private fun registerForWindowInsets(
view: View,
mostParent: View,
initialState: ViewState,
listener: OnApplyInsetsListener
) {
ViewCompat.setOnApplyWindowInsetsListener(
mostParent
) { v, insets ->
listener.onApplyInsets(view, insets, initialState)
// Always return the initial insets instance
insets
}
ViewCompat.requestApplyInsets(mostParent)
}
/**
* Returns the most parent view in its hierarchy
*/
private fun getMostParentView(view: View): View =
view.parent.run {
if (this != null && this is View && this.id != android.R.id.content) {
getMostParentView(this)
} else view
}