Bottomsheet with edit text moved up by keyboard

后端 未结 2 454
庸人自扰
庸人自扰 2021-01-06 09:49

I have bottomsheet fragment what shows to user answears to his comment. At the bottom of bottom sheet we have edit text, where user can add new comment. So, when soft keyboa

2条回答
  •  自闭症患者
    2021-01-06 10:26

    I ended up getting a satisfactory result with the following code: use this in setupDialog(dialog: Dialog, style: Int) method in BottomSheetFragment

    dialog.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE)
        dialog.setOnShowListener {
            val bottomSheetDialog = dialog as BottomSheetDialog
            val bottomSheet = bottomSheetDialog.findViewById(android.support.design.R.id.design_bottom_sheet) as FrameLayout?
            BottomSheetBehavior.from(bottomSheet!!).state = BottomSheetBehavior.STATE_EXPANDED
        }
    

提交回复
热议问题