有一个扩展 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 {
...
}
}
这就是我对对话框的所有代码。
最佳答案
结合@nntk 和@CKotlin 答案对我来说是诀窍。我设法用这段代码解决了这个问题:
override fun onStop() {
super.onStop()
dialog?.window?.setWindowAnimations(-1)
}
编辑:在 Android < P (API 28) 上,它使应用程序不响应触摸事件。所以要么你不使用它,要么你需要用支票包围它:
override fun onStop() {
super.onStop()
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.P) {
dialog?.window?.setWindowAnimations(-1)
}
}
关于android - 从后台返回时,BottomSheetDialogFragment 禁用动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57110736/