PopupWindow的基本應用

//創建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;
                    }
                });
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章