直接上代码
//设置空白的背景色 WindowManager.LayoutParams lp = getActivity().getWindow().getAttributes(); lp.alpha = 0.3f; getActivity().getWindow().setAttributes(lp); // 用于PopupWindow的View View contentView = LayoutInflater.from(getContext()).inflate(R.layout.quote_info_pop, null, false); // 创建PopupWindow对象,其中: // 第一个参数是用于PopupWindow中的View,第二个参数是PopupWindow的宽度, // 第三个参数是PopupWindow的高度,第四个参数指定PopupWindow能否获得焦点 PopupWindow window = new PopupWindow(contentView, getScreenWith() / 3 * 2, (int) getScreenHeight() / 3 * 2, true); // 设置PopupWindow的背景 window.setBackgroundDrawable(getResources().getDrawable(R.drawable.white_shap)); // 设置PopupWindow是否能响应外部点击事件 window.setOutsideTouchable(true); // 设置PopupWindow是否能响应点击事件 window.setTouchable(true); // 显示PopupWindow,其中: // 第一个参数是PopupWindow的锚点,第二和第三个参数分别是PopupWindow相对锚点的x、y偏移 listView = contentView.findViewById(R.id.list); quoteInfoAdapter = new QuoteInfoAdapter(getActivity