I need to make my app respond to the onscreen keyboard. So before API 30 I was just using
requireActivity().window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE)
but since this is deprecated now, I tried to use the solution the documentation states by adjusting the insets. At first it didn't seem to recognize the statusbar moving the view (including the toolbar) up. But I eventually (almost) managed it by writing this:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
requireActivity().window.setDecorFitsSystemWindows(false)
requireActivity().window.decorView.setOnApplyWindowInsetsListener { v, windowInsets ->
val imeHeight = windowInsets.getInsets(WindowInsets.Type.ime())
val statusBarsHeight = windowInsets.getInsets(WindowInsets.Type.statusBars())
v.setPadding( /*left */ imeHeight.left, // = 0
/*top */ statusBarsHeight.top, // = 66
/*right */ imeHeight.right, // = 0
/*bottom*/ imeHeight.bottom) // = 0
WindowInsets.Builder()
.setInsets(0, imeHeight)
.build()
}
}
The spacing seems to work. The Toolbar is not moving up any longer. However, it seems the padding I applied is cropping it instead. In the following picture you can see the normal (left) and the new (right) layout. The padding seems to overpaint the toolbar.
What am I doing wrong?
