【问题标题】:How to override dispatchTouchEvent in AlertDialog如何在 AlertDialog 中覆盖 dispatchTouchEvent
【发布时间】:2019-10-15 12:04:34
【问题描述】:

我有这个对话框。

 AlertDialog.Builder(context, R.style.AppTheme_AlertDialog_SettingsConfirm)
            .setTitle(dialogVo.title)
            .setMessage(dialogVo.message)
            .setCancelable(false)
            .setNegativeButton(
                dialogVo.messageOnNegativeBtn,
                dialogVo.onNegativeClickListener
            )
            .setPositiveButton(
                dialogVo.messageOnPositiveBtn,
                dialogVo.onPositiveClickListener
            )
            .create()

如何覆盖dispatchTouchEvent?

【问题讨论】:

  • 你能解释一下用例是什么吗?

标签: android dialog android-alertdialog


【解决方案1】:

不要使用 AlertDialog.Builder,而是使用 AlertDialog:

val alertDialog =object: AlertDialog(this,R.style.MyAlertDialogStyle) {
    override fun dispatchTouchEvent(ev: MotionEvent): Boolean {
        if (ev.action == MotionEvent.ACTION_DOWN) {
            ///TODO
        }
        return super.dispatchTouchEvent(ev)
    }

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-20
    • 2019-12-04
    • 2012-12-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多