DialogFragment不可取消

class LoadingDialog : DialogFragment() {
    ...
    
    override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {

        val layout = requireActivity().layoutInflater.inflate(R.layout.loading_view, null)
        val showText = layout.findViewById<TextView>(R.id.showMsgLoadingDialog)
        showText.setText(msg)
        val myDialog = requireActivity().run {
            val builder = AlertDialog.Builder(this)
            builder.setView(layout)
            builder.create()
        }
        myDialog.setCancelable(false) //返回键不可取消
        myDialog.setCanceledOnTouchOutside(false) //点击外部不取消
        isCancelable=false  //侧滑,Fragment不可取消
        return myDialog
    }
    ...
    
}

你可能感兴趣的:(零碎)