如何解雇与点击对话外的对话? [英] How to dismiss the dialog with click on outside of the dialog?
问题描述
我已经实现了我的应用程序自定义对话框。我想实现当用户点击对话外,对话框将被解雇。 我有什么做的呢?
I have implemented a custom dialog for my application. I want to implement that when the user clicks outside the dialog, the dialog will be dismissed. What do I have to do for this?
推荐答案
您可以使用 dialog.setCanceledOnTouchOutside(真);
,如果你摸之外,将关闭对话框该对话框。
You can use dialog.setCanceledOnTouchOutside(true);
which will close the dialog if you touch outside of the dialog.
喜欢的东西,
Dialog dialog = new Dialog(context)
dialog.setCanceledOnTouchOutside(true);
或者,如果你的对话中无模式的话,
Or if your Dialog in non-model then,
1 - 设置标记 - FLAG_NOT_TOUCH_MODAL
为您的对话窗口属性。
1 - Set the flag-FLAG_NOT_TOUCH_MODAL
for your dialog's window attribute
Window window = this.getWindow();
window.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
2 - 添加另一个标志到Windows性能,, FLAG_WATCH_OUTSIDE_TOUCH
- 这个人是通过对话,接受它的可见区域以外的触摸事件
2 - Add another flag to windows properties,, FLAG_WATCH_OUTSIDE_TOUCH
- this one is for dialog to receive touch event outside its visible region.
3 - 覆盖的onTouchEvent()
的对话框,并检查操作类型。如果动作类型是
MotionEvent.ACTION_OUTSIDE
的意思是,用户在对话框区域外进行交互。因此,在这种情况下,你可以dimiss你的对话框或者决定你想要的执行。
鉴于plainprint?
3 - Override onTouchEvent()
of dialog and check for action type. if the action type is
'MotionEvent.ACTION_OUTSIDE
' means, user is interacting outside the dialog region. So in this case, you can dimiss your dialog or decide what you wanted to perform.
view plainprint?
public boolean onTouchEvent(MotionEvent event)
{
if(event.getAction() == MotionEvent.ACTION_OUTSIDE){
System.out.println("TOuch outside the dialog ******************** ");
this.dismiss();
}
return false;
}
有关更多信息看如何解雇一个自定义对话框基于接触点?并 如何在对话框区域外的感动解散你的无模式对话框,
这篇关于如何解雇与点击对话外的对话?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!