防止BottomSheetDialogFragment隐藏键盘

问题描述

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

我正在这显示BottomSheetDialogFragment:

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

解决方法

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

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