• <small id='rQeWU'></small><noframes id='rQeWU'>

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

      <tfoot id='rQeWU'></tfoot>

        问题关闭弹出窗口

        时间:2024-04-14

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

              1. <small id='J1U3r'></small><noframes id='J1U3r'>

                  <bdo id='J1U3r'></bdo><ul id='J1U3r'></ul>
                • 本文介绍了问题关闭弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我实现了一个弹出菜单,点击一个按钮就会显示出来.这是我的 onclick 方法.

                  I have a popup menu implemented , which shows up on click of a button. This is my onclick method.

                  public void showOverflow(View view) {
                  
                      boolean click = true;
                      Button action = (Button) findViewById(R.id.btbAction);
                  
                      LayoutInflater inflater = (LayoutInflater) main.this
                              .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                      View popupView = inflater.inflate(R.layout.overflow_layout, null);
                      final PopupWindow pw = new PopupWindow(popupView,
                              LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
                      pw.setOutsideTouchable(true);
                      if (click) {
                          pw.showAsDropDown(action, 0, 0);
                          click = false;
                      } else {
                          pw.dismiss();
                          click = true;
                      }
                  }
                  

                  单击按钮时会显示弹出窗口.现在,问题是当我在弹出窗口之外触摸时,窗口没有被关闭.我尝试将此属性设置为弹出窗口

                  The popup window shows up when the button is clicked. Now, the problem is that the window is not dismissed when i touch outside the popup window. I tried setting this property to the popup window

                  pw.setOutsideTouchable(true);
                  

                  事情保持不变.请帮我解决这个问题

                  Things remain the same. Please help me fix this

                  推荐答案

                  您应该将 setOutsideTouchable 调用的参数更改为 true:pw.setOutsideTouchable(false);

                  You should change the setOutsideTouchable call's parameter to true: pw.setOutsideTouchable(false);

                  控制弹出窗口是否会被通知外部的触摸事件它的窗口.这仅对可触摸的弹出窗口有意义但不可聚焦,这意味着窗口外的触摸将是送到后面的窗户.默认为 false.

                  Controls whether the pop-up will be informed of touch events outside of its window. This only makes sense for pop-ups that are touchable but not focusable, which means touches outside of the window will be delivered to the window behind. The default is false.

                  如果弹出窗口正在显示,调用此方法只会生效下次显示弹出窗口时或通过手动调用其中一个update() 方法.

                  If the popup is showing, calling this method will take effect only the next time the popup is shown or through a manual call to one of the update() methods.

                  参数:touchable true 如果弹出窗口应该接收外部触摸事件,false 否则

                  Parameters: touchable true if the popup should receive outside touch events, false otherwise

                  另一方面,click 局部变量应该做什么?它设置为 true,所以它总是强制 pw 弹出,无论何时调用 showOverflow 方法,并且无缘无故稍后设置为 false,因为它的生命周期在您离开该方法时结束.

                  On the other hand, what is the click local variable supposed to do? It is set to true, so it will always force the pw to pop up, whenever the showOverflow method is called, and for no reason it is set to false later, because it's life cycle ends as you leave that method.

                  您的代码应如下所示:

                  private LayoutInflater inflater;
                  private Button action;
                  private PopupWindow pw;
                  private View popupView;
                  /*
                   * (non-Javadoc)
                   * @see android.app.Activity#onCreate(android.os.Bundle)
                   */
                  @Override
                  protected void onCreate(Bundle savedInstanceState)
                  {
                      super.onCreate(savedInstanceState);
                      setContentView(R.layout.splash);
                      inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                      popupView = inflater.inflate(R.layout.overflow_layout, null, false);
                  
                      action = (Button) findViewById(R.id.action);
                      action.setOnClickListener(this);
                  }
                  
                  public void showOverflow()
                  {
                      pw = new PopupWindow(getApplicationContext());
                      pw.setWidth(WindowManager.LayoutParams.WRAP_CONTENT);
                      pw.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
                      pw.setOutsideTouchable(true);
                  
                      pw.setContentView(popupView);
                      pw.showAsDropDown(action, 0, 0);
                  }
                  

                  如果您在 Activity 类中,则应使用 getApplicationContext().否则你应该得到 Context 作为参数.

                  The getApplicationContext() shoud be used in case you are inside an Activity class. Otherwise you should get the Context as a parameter.

                  这篇关于问题关闭弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:显示一个 PopupWindow 集中 下一篇:如何像弹出窗口一样打开新的uiview?

                  相关文章

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

                • <legend id='WY6lu'><style id='WY6lu'><dir id='WY6lu'><q id='WY6lu'></q></dir></style></legend>
                  <tfoot id='WY6lu'></tfoot>

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

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