Keyboard hides BottomSheetDialogFragment

后端 未结 6 1419
走了就别回头了
走了就别回头了 2020-12-04 13:22

There are more fields below the keyboard. This happened when i updated the support library. I know it\'s Kotlin but it looks almost the same as java. How do I fix this issue

6条回答
  •  不知归路
    2020-12-04 14:09

    This solution worked for me after spending 5 hours without luck:

    Step #1:

    Add this code to your styles.xml (located in res\values folder)

    
    

    The key here is to set android:windowIsFloating -> false, if it is true your code will not work! Therefor i used rather android:backgroundDimEnabled and android:backgroundDimAmount to make background looks transparent with beautiful overlay.

    Step #2:

    Write this function to adjust it programmatically (note it is not optional, you need to perform both steps #1 and #2):

    private fun showDialog() {
    
        BottomSheetDialog(requireActivity(), R.style.CustomizedBottomDialogStyle).apply {
    
            window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE)
    
            setOnShowListener {
                Handler().post {
                    val bottomSheet = findViewById(R.id.design_bottom_sheet) as? FrameLayout
                    bottomSheet?.let {
                        BottomSheetBehavior.from(it).state = STATE_EXPANDED
                    }
                }
            }
    
            setContentView(R.layout.dialog_layout)
    
            // Your code goes here....
    
            show()
        }
    }
    

提交回复
热议问题