如何使用PopupWindow:
//初始化popuwindow
LayoutInflater mLayoutInflater = (LayoutInflater) SubList.this.getSystemService(LAYOUT_INFLATER_SERVICE);
View title_popunwindwow = mLayoutInflater.inflate(R.layout.sublist_popuwindow, null);
PopupWindow mPopupWindow = new PopupWindow(title_popunwindwow, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,true);
mPopupWindow.setBackgroundDrawable(new BitmapDrawable());//点击窗口外消失
mPopupWindow.setOutsideTouchable(true);
显示PopupWindow:
mPopupWindow.showAsDropDown(findViewById(R.id.titlebar_center),-43,0);
pw.showAtLocation(view, Gravity.CENTER, -(view.getWidth()),y);
若需要监听PopUpWindow里控件的事件,如PopUpWindow里面一个按钮的事件,那么就需要调用方法setFocusable(true)获得焦点,并且在调用setFocusable(true)方法后,可以通过Back(返回)菜单使PopUpWindow dimiss;另外调用方法setOutsideTouchable(true)后,点击PopUpWindow外面的控件也可以使得PopUpWindow dimiss。需要顺利让PopUpWindow dimiss;PopUpWindow的背景不能为空。