View contentView = View.inflate(getActivity(), R.layout.popupwindow_layout, null);
PopupWindow popupWindow= new PopupWindow(contentView,RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT, true);
ColorDrawable cd = new ColorDrawable(Color.parseColor("#ffffff"));
popupWindow.setBackgroundDrawable(cd); 要让点击PopupWindow之外的地方PopupWindow消失需要调用
popupWindow.showAsDropDown(LeftTitle); 相对某个控件的位置(正左下方),无偏移
popupWindow.dismiss(); 取消
popupWindow.setFocusable(true); // 设置PopupWindow可获得焦点
popupWindow.setTouchable(true); // 设置PopupWindow可触摸
showAsDropDown(View anchor):相对某个控件的位置(正左下方),无偏移
showAsDropDown(View anchor, int xoff, int yoff):相对某个控件的位置,有偏移
showAtLocation(View parent, int gravity, int x, int y):相对于父控件的位置(例如正中央Gravity.CENTER,下方Gravity.BOTTOM等),可以设置偏移或无偏移
转载请注明原文地址: https://ju.6miu.com/read-1000345.html