【问题标题】:BottomSheetDialogFragment allow user to touch outsideBottomSheetDialogFragment 允许用户触摸外部
【发布时间】:2019-02-21 02:14:55
【问题描述】:

我正在尝试从视频列表中启动 BottomSheetDialogFragment,一旦打开,就会播放视频,但是我希望允许用户在 BottomSheetDialogFragment 打开时从列表中选择其他视频。

我尝试了什么:

   <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>

和:

    @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)
}

以上所有内容都在 DialogFragment 中有效,但在 BottomSheetDialogFragment 中无效。

【问题讨论】:

  • 不确定BottomSheetDialogFragment 但您可以使用Layoutandroid.support.design.widget.BottomSheetBehavior 实现类似的效果..
  • 您找到解决方案了吗?
  • @elementstyle 是的,我做到了。我没有显示底部工作表,而是使用了 fragmentManager “add”方法。这对我有用,因为我有一个活动多片段应用程序。
  • 我回答这个问题,请查看此链接:stackoverflow.com/a/58689894/4519936

标签: android bottom-sheet dialogfragment


【解决方案1】:

我认为您想念的东西如下所示;将其添加到您的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
   }
}

坐标更改是必要的,因为此模式位于不同的装饰视图中。否则,点击可能位于不同的位置。 但是,当您后面有一些输入字段时,就会出现问题 - 直到现在我还没有设法正确显示它的键盘;我添加了窗口标志FLAG_NOT_FOCUSABLE,但它仍然在模态下显示键盘(不在下方,模态覆盖键盘)。

【讨论】:

    猜你喜欢
    • 2013-03-01
    • 1970-01-01
    • 2017-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多