<legend id='Bc6en'><style id='Bc6en'><dir id='Bc6en'><q id='Bc6en'></q></dir></style></legend>

<small id='Bc6en'></small><noframes id='Bc6en'>

  • <tfoot id='Bc6en'></tfoot>

    1. <i id='Bc6en'><tr id='Bc6en'><dt id='Bc6en'><q id='Bc6en'><span id='Bc6en'><b id='Bc6en'><form id='Bc6en'><ins id='Bc6en'></ins><ul id='Bc6en'></ul><sub id='Bc6en'></sub></form><legend id='Bc6en'></legend><bdo id='Bc6en'><pre id='Bc6en'><center id='Bc6en'></center></pre></bdo></b><th id='Bc6en'></th></span></q></dt></tr></i><div id='Bc6en'><tfoot id='Bc6en'></tfoot><dl id='Bc6en'><fieldset id='Bc6en'></fieldset></dl></div>

        • <bdo id='Bc6en'></bdo><ul id='Bc6en'></ul>

        如何通过单击对话框外部来关闭对话框?

        时间:2023-08-31

      1. <legend id='mn2al'><style id='mn2al'><dir id='mn2al'><q id='mn2al'></q></dir></style></legend><tfoot id='mn2al'></tfoot>
          <i id='mn2al'><tr id='mn2al'><dt id='mn2al'><q id='mn2al'><span id='mn2al'><b id='mn2al'><form id='mn2al'><ins id='mn2al'></ins><ul id='mn2al'></ul><sub id='mn2al'></sub></form><legend id='mn2al'></legend><bdo id='mn2al'><pre id='mn2al'><center id='mn2al'></center></pre></bdo></b><th id='mn2al'></th></span></q></dt></tr></i><div id='mn2al'><tfoot id='mn2al'></tfoot><dl id='mn2al'><fieldset id='mn2al'></fieldset></dl></div>
            <bdo id='mn2al'></bdo><ul id='mn2al'></ul>
                <tbody id='mn2al'></tbody>

              <small id='mn2al'></small><noframes id='mn2al'>

                  本文介绍了如何通过单击对话框外部来关闭对话框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我已经为我的应用程序实现了一个自定义对话框.我想实现当用户在对话框外单击时,对话框将被关闭.我该怎么办?

                  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(true); 如果您触摸对话框之外,它将关闭对话框.

                  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);
                  

                  或者,如果您的 Dialog 在非模型中,那么,

                  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 - 向窗口属性添加另一个标志,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' 表示用户在对话区域之外进行交互.因此,在这种情况下,您可以关闭对话或决定要执行的操作.查看普通版?

                  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;  
                  }  
                  

                  有关更多信息,请查看 如何关闭基于接触点的自定义对话框? 和如何关闭非模态对话框,在对话区域外触摸时

                  For more info look at How to dismiss a custom dialog based on touch points? and How to dismiss your non-modal dialog, when touched outside dialog region

                  这篇关于如何通过单击对话框外部来关闭对话框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何使警报对话框填充 90% 的屏幕尺寸? 下一篇:如何更改 Android 5.0 的 DatePicker 对话框颜色

                  相关文章

                  最新文章

                  • <bdo id='15bPx'></bdo><ul id='15bPx'></ul>
                  <legend id='15bPx'><style id='15bPx'><dir id='15bPx'><q id='15bPx'></q></dir></style></legend>

                    <tfoot id='15bPx'></tfoot>

                    <i id='15bPx'><tr id='15bPx'><dt id='15bPx'><q id='15bPx'><span id='15bPx'><b id='15bPx'><form id='15bPx'><ins id='15bPx'></ins><ul id='15bPx'></ul><sub id='15bPx'></sub></form><legend id='15bPx'></legend><bdo id='15bPx'><pre id='15bPx'><center id='15bPx'></center></pre></bdo></b><th id='15bPx'></th></span></q></dt></tr></i><div id='15bPx'><tfoot id='15bPx'></tfoot><dl id='15bPx'><fieldset id='15bPx'></fieldset></dl></div>
                  1. <small id='15bPx'></small><noframes id='15bPx'>