查了查 大部分有两个方法
方法1:
protected void showPopupWindow() {
//Context mContext = HahItemActivity.this;
LayoutInflater mLayoutInflater = (LayoutInflater)this.getSystemService(LAYOUT_INFLATER_SERVICE);
//保存转发等视图
View xuanz_popunwindwow = mLayoutInflater.inflate(
R.layout.popwindow_image, null);
//转化为popunwindow
mPopupWindow= new PopupWindow(xuanz_popunwindwow,
LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
mPopupWindow.setBackgroundDrawable(new BitmapDrawable());
mPopupWindow.setFocusable(true);
mPopupWindow.setOutsideTouchable(true);
mPopupWindow.update();
//设置显示
mPopupWindow.showAtLocation(findViewById(R.id.hahaimage_pop_layout), Gravity.CENTER, 0,0);
//设置显示mPopupWindow.showAtLocation(findViewById(R.id.hahaimage_pop_layout), Gravity.CENTER, 0,0);
mPopupWindow.setBackgroundDrawable(new BitmapDrawable()); //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
mPopupWindow.setFocusable(true); //!获取焦点!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1
mPopupWindow.setOutsideTouchable(true); mPopupWindow.update(); //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1
上面这三个语句就可以控制啦点击别的地方消失啦,要写在ShowAtLocation之前
.()设置popupWindow.setFocusable(true); 这样才能让popupWindow里面的布局控件获得点击的事件否则就被它的父亲view给拦截了。
方法2 :(这种方法可以处理popupwindows dimiss的时候一些其他的操作,比如让其他控件的隐藏,消失等):
代码如下popupWindow.setFocusable(false);//focusable要为false(不设置默认的就是False);
//这是Activity 的OnTouchEvent。OnTouchEvent代表的是Activity 获得事件(即为PopupWindow之外)
@Override
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
if (popupWindow != null && popupWindow.isShowing()) {
popupWindow.dismiss();
popupWindow = null;
}
return super.onTouchEvent(event);
}
注:亲测1可行