2013-10-21 55 views
1

我有一个popupWindow showAsDropDown按钮单击和此popupWindow setOutsideTouchable(true),我想切换显示弹出式,当我点击我的按钮,但也要解雇,当我点击以外的弹出。问题是,外界触摸按钮前点击打来电话,之后,我的弹出窗口隐藏和显示。 有没有办法做到这一点?Android PopupWindow防止停靠点击

固定

我想通了,问题是,我popupwindow不是重点,我要叫

popupWindow.setFocusable(true); 

修复它。

回答

0

Please check this out.

如果我以正确的方式理解,

// Pop up Window showing 

    LayoutInflater layoutInflater = (LayoutInflater) getBaseContext() 
      .getSystemService(LAYOUT_INFLATER_SERVICE); 
    popupView = layoutInflater.inflate(R.layout.menu_popup, null); 
    popupWindow = new PopupWindow(popupView, LayoutParams.WRAP_CONTENT, 
      LayoutParams.WRAP_CONTENT); 
    popupWindow.setOutsideTouchable(true); 

// Add setBackgroundDrawable to the pop up window to close the dialog : 

     popupWindow.setBackgroundDrawable(getResources().getDrawable(
      android.R.color.transparent)); 
    popupWindow.setTouchable(true); 

使用下面的检查,可以按你们的要求

findViewById(R.id.topMenu).setOnClickListener(
      new View.OnClickListener() { 

       @Override 
       public void onClick(View v) { 
        // TODO Auto-generated method stub 

         popupWindow 
           .showAsDropDown(findViewById(R.id.topMenu)); 

      }); 

我已经检查这个显示弹出式菜单。它工作正常。

+0

yes我的代码很相似,但'setOutsideTouchable(true)'不适用于onClick 'isShowing()'每次都是false,因为在触发onClick之前关闭弹出框。 – Rumen

+0

你想做什么做什么呢?当用户在外面接触时,你想关闭弹出窗口? –

+0

是的,我想外面关闭时,触摸也有触发锚。像[这](http://searchengineland.com/figz/wp-content/seloads/2012/02/google-mobile-navigation-ui-test-feb2012-2.png),当你点击锚关闭并打开窗户,但也可以在外面触摸时关闭。 – Rumen