setOnApplyWindowInsetsListener - statusBar颜色问题

pat*_*036 6 android windowinsets

为什么当我使用

setOnApplyWindowInsetsListener

状态栏颜色消失?

 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
    }
}
Run Code Online (Sandbox Code Playgroud)

Ger*_*eto 1

而不是使用ViewCompat.setOnApplyWindowInsetsListener(view),使用window.decorView.setOnApplyWindowInsetsListener,返回view.onApplyWindowInsets(insets)像这样:

 window.decorView.setOnApplyWindowInsetsListener { view, insets ->

            //do your thing here

            view.onApplyWindowInsets(insets)
 }
Run Code Online (Sandbox Code Playgroud)

就是这样。

希望能帮助到你!