ViewCompat.setOnApplyWindowInsetsListener() changes background of system navigation bar

2.9k Views Asked by At

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)

1

There are 1 best solutions below

0
On

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