为什么我使用
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
}
}
不使用ViewCompat.setOnApplyWindowInsetsListener(view)
,使用window.decorView.setOnApplyWindowInsetsListener
,返回view.onApplyWindowInsets(insets)
如下:
window.decorView.setOnApplyWindowInsetsListener { view, insets ->
//do your thing here
view.onApplyWindowInsets(insets)
}
就是这样。
希望有帮助!