//創建popupWindow
popupWindow = new PopupWindow(getActivity());
//加載popupWindow佈局
View inflate = View.inflate(getActivity(), R.layout.home_pop_item, null);
popupWindow.setContentView(inflate);
//設置popupWindow寬高
popupWindow.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
popupWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
//設置可觸碰
popupWindow.setOutsideTouchable(true);
popupWindow.setFocusable(true);
popupWindow.setTouchable(true);
//設置顯示位置
popupWindow.showAsDropDown(ivMenu);
//設置popupWindow關閉
popupWindow.dismiss();
popupWindow.setTouchInterceptor(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {
popupWindow.dismiss();
return true;
}
return false;
}
});