popupwindow 显示后,当触屏点击非popupwindow显示区域,如何让这个popupwindow窗口消失?请帮忙,谢谢!!

解决方案 »

  1.   

      if (pop == null) {
                      pop = new PopupWindow(menuview, screenWidth/2, screenHeight/2, true); 
                      pop.setBackgroundDrawable(this.getResources().getDrawable(R.drawable.select_device_bg));
                      pop.setTouchInterceptor(new OnTouchListener(){ public boolean onTouch(View v, MotionEvent event) {
    // TODO Auto-generated method stub

    if(event.getAction() == MotionEvent.ACTION_OUTSIDE)
    {
    pop.dismiss();
    }
    return false;
    }
                       
                      });
                    //  pop.setAnimationStyle(R.style.PopupAnimation); 
                      pop.setOutsideTouchable(true);  
                      pop.showAsDropDown(view, Gravity.CENTER_HORIZONTAL, 0);
                      pop.update();  
            } else {  
            if (pop.isShowing()) {
                      pop.dismiss();  
                      pop = null; 
      

  2.   

    谢谢楼上。主要是没有设置setBackgroundDrawable,设置以后点击非PopupWindow就可以消失了。