3

I'm trying to launch a BottomSheetDialogFragment from list of videos, once opened, a video will play, however I want to allow the user to select other videos from the list while the BottomSheetDialogFragment is open.

What I tried:

   <style name="CustomBottomSheetDialogTheme" parent="Theme.Design.Light.BottomSheetDialog">
    <item name="bottomSheetStyle">@style/CustomBottomSheetStyle</item>
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:colorBackground">@android:color/transparent</item>
    <item name="android:backgroundDimEnabled">false</item>
    <item name="android:backgroundDimAmount">0</item>
    <item name="android:windowFrame">@null</item>
    <item name="android:windowIsFloating">true</item>
</style>

<style name="CustomBottomSheetStyle" parent="Widget.Design.BottomSheet.Modal">
    <item name="android:background">@android:color/transparent</item>
</style>

and:

    @SuppressLint("RestrictedApi")
override fun setupDialog(dialog: Dialog?, style: Int) {
    super.setupDialog(dialog, style)
    dialog?.window?.setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)
    dialog?.window?.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND)
    dialog?.setCanceledOnTouchOutside(false)
    dialog?.setCancelable(false)
}

All the above works in a DialogFragment but does not in a BottomSheetDialogFragment.

Roudi
  • 1,249
  • 2
  • 12
  • 26
  • Not sure about `BottomSheetDialogFragment` But you can achieve similar thing with `Layout` with `android.support.design.widget.BottomSheetBehavior`.. – ADM Feb 21 '19 at 04:24
  • Did you find a solution for this? – elementstyle Apr 11 '19 at 10:29
  • @elementstyle yes i did. Instead of showing the bottom sheet i used the fragmentManager "add" method. That worked for me since i have a single activity multiple fragments app. – Roudi Apr 12 '19 at 06:34
  • I answer to this question, please check this link: https://stackoverflow.com/a/58689894/4519936 – mohsen Nov 04 '19 at 10:38

1 Answers1

1

I think the thing you miss is something like below; add it in your dialog.setOnShowListener

it.findViewById<View>(R.id.touch_outside)?.apply {
   setOnTouchListener { v, event ->
      event.setLocation(event.rawX - v.x, event.rawY - v.y)
            
      activity?.dispatchTouchEvent(event)
      false
   }
}

coordinates change is necessary because this modal is in the different decor view. Otherwise, clicks could be in a different place. However, there is a problem when you have some input field behind - till now I did not manage to show the keyboard for it correctly; I added window flag FLAG_NOT_FOCUSABLE but it still shows the keyboard under the modal (not below, modal covers keyboard).

Witold Kupś
  • 524
  • 7
  • 14