检测 Android 中对话框窗口的点击
我有一个对话框:
final Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.location_dialog);
dialog.setTitle("My dialog");
dialog.setMessage("My dialog's content");
dialog.setCancelable(true);
dialog.setCanceledOnTouchOutside(true);
dialog.show();
我希望能够检测对话框线上方和线外的触摸。 我可以使用内置方法轻松检测对话框区域之外的任何触摸,
dialog.setCanceledOnTouchOutside(true);
但是如何检测该区域内的触摸呢?
I have a dialog:
final Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.location_dialog);
dialog.setTitle("My dialog");
dialog.setMessage("My dialog's content");
dialog.setCancelable(true);
dialog.setCanceledOnTouchOutside(true);
dialog.show();
I want to be able to detect touches over and outside the dialog box's lines.
I can easily detect any touches outside the dialog box area with the build-in method
dialog.setCanceledOnTouchOutside(true);
But how can I detect the touches inside this area?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
创建 Dialog 的扩展并覆盖必要的方法: dispatchTouchEvent 或 onTouchEvent (来自文档:这对于处理发生在窗口边界之外的触摸事件最有用,因为没有视图可以接收它。)
更新:
Create an extension of Dialog and override necessary method: dispatchTouchEvent or onTouchEvent (From docs: This is most useful to process touch events that happen outside of your window bounds, where there is no view to receive it.)
Updated: