android中弹出一个popupwindow,根据网上查的,如果要做到点击空白,弹窗消失,必须:
1、PopupWindow(layerSelector, 60, 30, true),第三个参数必须为true, 或者window.setTouchable(true);
2、必须window.setBackgroundDrawable(new BitmapDrawable())。
按照这个做了,还是不消失,整个应用中都不能点击了,包括返回键都失效了。
我以为碰到鬼了,经过折腾、观察,找到疑点,见下面代码红色部分,原先是写在前面的,移到蓝色的哪一行就可以了,一切OK。
LayoutInflater mLayoutInflater = LayoutInflater.from(this);
View layerSelector = mLayoutInflater.inflate(R.layout.maplayer, null);PopupWindow window = new PopupWindow(layerSelector, 60, 30, true);
//window.showAsDropDown(findViewById(R.id.viewselector));
window.setTouchable(true);
window.setBackgroundDrawable(new BitmapDrawable(getResources(), (Bitmap)null));
window.setOutsideTouchable(true);
window.showAsDropDown(findViewById(R.id.viewselector));