防止BottomSheetDialogFragment隐藏键盘

时间:2020-08-26 11:10:40

标签: android keyboard bottomsheetdialogfragment

如果我在当前活动/片段中打开了键盘,则当我显示BottomSheetDialogFragment时,键盘会被关闭,但我希望键盘停留在BottomSheetDialogFragment后面的背景中。当我显示BottomSheetDialogFragment时,是否有办法使键盘在bottomSheetDialogFragment后面保持打开状态,并防止键盘被关闭?

我正在这样显示BottomSheetDialogFragment:

modalBottomSheet.show(
                (activity as AppCompatActivity).supportFragmentManager,
                ModalBottomSheet.TAG + System.currentTimeMillis().toString()
)

1 个答案:

答案 0 :(得分:1)

我知道了。在您的BottomSheetDialogFragment的子类中,在方法中:重写fun setupDialog(dialog:Dialog,style:Int),请执行以下操作:

dialog.window?.setFlags(
            WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
            WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);