当单击发生在对话框外时如何触发事件 [英] How do I fire an event when click occurs outside a dialog

查看:29
本文介绍了当单击发生在对话框外时如何触发事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何解决我遇到的问题.

I would like to know how to solve a problem I've got.

我有一个在活动中弹出的对话框.对话框不会覆盖整个屏幕,因此活动中的按钮仍会显示.当使用 dialog.setCanceledOnTouchOutside(true);

I have a Dialog which pops up in an activity. The Dialog doesn't cover the whole screen, so the buttons from the activity still show. I can easily close the dialog when there is a touch outside the dialog's bounds with dialog.setCanceledOnTouchOutside(true);

但是,我想要做的是,如果单击超出 Dialog 的边界,则触发一个事件(例如,如果有人触摸主 Activity 上的按钮,它应该关闭 Dialog 并同时触发该事件).

However what I want to do is fire an event if a click is outside the Dialog's bounds (e.g if someone touches a button on the main Activity, it should close the Dialog and fire that event at the same time).

推荐答案

It Works for me,,

It Works For me,,

        Window window = dialog.getWindow();
        window.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
                WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
        window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);

        dialog.show();

看到这个 http:///developer.android.com/reference/android/view/WindowManager.LayoutParams.html#FLAG_NOT_TOUCH_MODAL

这篇关于当单击发生在对话框外时如何触发事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆