Search code examples
android

SOFT_INPUT_ADJUST_RESIZE deprecated starting android 30


I used SOFT_INPUT_ADJUST_RESIZE in order to show all content when keyboard pops up. Following documentation, I added new code pieces:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
    requireActivity().window.setDecorFitsSystemWindows(false)
}

and

binding.constraintLayoutRoot.setOnApplyWindowInsetsListener { _, windowInsets ->
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
        val insets = windowInsets.getInsets(WindowInsets.Type.ime() or WindowInsets.Type.systemGestures())
        insets
    }

    windowInsets
}

For some reason, view does not resize based on the fact if the keyboard appears or not.


Solution

  • Can you try doing the following, I think we have to manually add the padding for the keyboard now.

    binding.root.setOnApplyWindowInsetsListener { _, windowInsets ->
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
            val imeHeight = windowInsets.getInsets(WindowInsets.Type.ime()).bottom
            binding.root.setPadding(0, 0, 0, imeHeight)
            val insets = windowInsets.getInsets(WindowInsets.Type.ime() or WindowInsets.Type.systemGestures())
            insets
        }
    
        windowInsets
    }