0

If I have keyboard opened in current activity/fragment, when I present the BottomSheetDialogFragment, keyboard gets dismissed, but I want the keyboard to stay up in the background behind the BottomSheetDialogFragment. Is there a way to keep keyboard opened behind bottomSheetDialogFragment when I show the BottomSheetDialogFragment and prevent keyboard from being dismissed?

I am showing the BottomSheetDialogFragment like this:

modalBottomSheet.show(
                (activity as AppCompatActivity).supportFragmentManager,
                ModalBottomSheet.TAG + System.currentTimeMillis().toString()
)
coolcool1994
  • 3,704
  • 4
  • 39
  • 43
  • When you create system default Alert Dialog, the keyboard stays open behind the alert Dialog. And also when you open a new Fragment via navigation component, keyboard stays open from the previous fragment. So I think there might be a way, and I can't seem to figure it out. – coolcool1994 Aug 26 '20 at 13:09
  • So technically BottomShetDialogFragment is a fragment so keyboard should stay open when the new fragment is opened. It displays a the bottom sheet dialogue which is a dialog so keyboard should stay open. – coolcool1994 Aug 26 '20 at 13:10

1 Answers1

1

I figured it out. In your BottomSheetDialogFragment's subclass, in the method: override fun setupDialog(dialog: Dialog, style: Int), do:

dialog.window?.setFlags(
            WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
            WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
coolcool1994
  • 3,704
  • 4
  • 39
  • 43