ViewCompat.setOnApplyWindowInsetsListener() changes background of system navigation bar
Asked Answered
K

1

6

App normally has this navigation bar:

enter image description here

But when I add ViewCompat.setOnApplyWindowInsetsListener()

ViewCompat.setOnApplyWindowInsetsListener(window.decorView) { _, insets ->
    binding.showingKeyboard = insets.isVisible(WindowInsetsCompat.Type.ime())
    WindowInsetsCompat.CONSUMED
}

or

ViewCompat.setOnApplyWindowInsetsListener(window.decorView) { _, insets ->
    binding.showingKeyboard = insets.isVisible(WindowInsetsCompat.Type.ime())
    insets
}

it becomes like this

enter image description here

Why does it happen? I don't want this method to change anything. I just want to use it to detect if the virtual keyboard is visible or not (there are no other good methods to do it)

Kolnick answered 30/9, 2021 at 9:7 Comment(2)
I have answered this in this post: https://mcmap.net/q/112325/-hiding-bottom-navigation-bar-whilst-keyboard-is-present-androidBillon
Just return ViewCompat.onApplyWindowInsets(v, insets) instead of insets >> don't forget to set the 1st parameter to vSerafinaserafine
A
2

Call setOnApplyWindowInsetsListener on root view of your layout, not on window.decorView

Accolade answered 19/4, 2022 at 17:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.