setOnApplyWindowInsetsListener - statusBar color problem
Asked Answered
S

1

6

Why when I use

setOnApplyWindowInsetsListener

statusBar color disappears?

 fun isKeyboardVisible(view: View) {
    ViewCompat.setOnApplyWindowInsetsListener(view) { view, windowInsets ->
        val isKeyboardVisible = windowInsets.isVisible(WindowInsetsCompat.Type.ime())
        if (isKeyboardVisible) Toast.makeText(applicationContext, "opened", Toast.LENGTH_SHORT).show()
        else Toast.makeText(applicationContext, "closed", Toast.LENGTH_SHORT).show()

        windowInsets
    }
}
Squander answered 21/10, 2021 at 9:1 Comment(2)
Did you find an answer for this?Quiet
@dalemncy yes, check this post: https://mcmap.net/q/112325/-hiding-bottom-navigation-bar-whilst-keyboard-is-present-androidDamselfly
R
1

Instead of using ViewCompat.setOnApplyWindowInsetsListener(view), use window.decorView.setOnApplyWindowInsetsListener, returning view.onApplyWindowInsets(insets) like so:

 window.decorView.setOnApplyWindowInsetsListener { view, insets ->

            //do your thing here

            view.onApplyWindowInsets(insets)
 }

And that is it.

Hope it helps!

Revolve answered 13/1, 2023 at 21:47 Comment(1)
But it's required @RequiresApi(Build.VERSION_CODES.R)Solidstate

© 2022 - 2024 — McMap. All rights reserved.