1. 若需要监听PopUpWindow里控件的事件,如PopUpWindow里面一个按钮的事件,那么就需要调用方法setFocusable(true)获得焦点,并且在调用setFocusable(true)方法后,可以通过Back(返回)菜单使PopUpWindow dimiss;另外调用方法setOutsideTouchable(true)后,点击PopUpWindow外面的控件也可以使得PopUpWindow dimiss。需要顺利让PopUpWindow dimiss;PopUpWindow的背景不能为空。
2. 如图:输入框EditText下面为PopUpWindow
3.设置代码如下
PopupWindow popUpWin;
popUpWin=new PopupWindow(listView,edtUserName.getWidth(),LayoutParams.WRAP_CONTENT);
popUpWin.setBackgroundDrawable(new BitmapDrawable());
popUpWin.setFocusable(true);
popUpWin.setOutsideTouchable(true);
popUpWin.showAsDropDown(edtUserName);