【问题标题】:BottomSheetDialogFragment disable animation when returning from backgroundBottomSheetDialogFragment 从后台返回时禁用动画
【发布时间】:2019-07-19 10:41:36
【问题描述】:

有一个扩展 BottomSheetDialogFragment 的类

当我将对话框设置为显示时,会出现从底部动画的幻灯片并显示对话框。现在,如果我将应用程序设置为后台,然后将其带回前台,则已经显示的对话框会在动画中执行相同的幻灯片。

如何禁用此功能,即如果对话框已显示,将应用程序发送到后台,然后前台不启动动画?

显示如下对话框:

dialog = MyDialogFragment()
dialog?.run {
    val args = Bundle()
    ....
    arguments = args
    show(this@MyFragment.fragmentManager, tag)
}

对话框类只有这个:

class MyDialogFragment : BottomSheetDialogFragment() {

    var listener: Listener? = null

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        // inflate view
        // Given the arguments, sets up the ui

        return view
    }

    interface Listener {
        ...
    }
}

这就是我对对话框的所有代码。

【问题讨论】:

  • 这个方法在哪里调用 show(this@MyFragment.fragmentManager, tag)
  • 在MyFragment
  • 是否在任何生命周期感知方法上,同时来自后台@Favolas
  • 显示对话框的方法是从 LiveData observable 调用的,但我检查了对话框是否已经显示,如果是,则不再显示。
  • 你解决了这个问题吗?

标签: android bottom-sheet


【解决方案1】:

结合@nntk 和@CKotlin 答案对我来说是诀窍。我设法用这段代码解决了这个问题:

override fun onStop() {
    super.onStop()
    dialog?.window?.setWindowAnimations(-1)
}

编辑: 在 Android

override fun onStop() {
    super.onStop()
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.P) {
        dialog?.window?.setWindowAnimations(-1)
    }
}

【讨论】:

  • 感谢分享,有没有找到其他版本

    stackoverflow.com/questions/65161454/…

  • 不幸的是我还没有找到其他版本的解决方案

  • 您好,感谢您的回复,不久前我悬赏了它,有人找到了有效的答案!
【解决方案2】:

覆盖BottomSheetDialogFragment中的onStop()方法

比如

@Override
public void onStop() {
    super.onStop();
    getDialog().show();  // important

}

【讨论】:

    【解决方案3】:

    我正在处理同样的问题。我还没有完全解决这个问题,但我可以通过执行以下操作来阻止上滑动画在恢复时出现:

        override fun onResume() {
            super.onResume()
            // Disable dialog window animations for this instance
            dialog?.window?.setWindowAnimations(-1)
        }
    

    但这并不能阻止背景渐变的动画效果,因此背景阴影会显示、消失,然后再次显示。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多