1:点击需要弹框按钮传控件id(popwindow显示在哪个view下方就传哪个id)
case R.id.edit_dz:
showPopupWindow(editDz);
break;
2:显示弹框
private void showPopupWindow(TextView view) {
//加载布局
View inflate = LayoutInflater.from(VipRZActivity.this).inflate(R.layout.popupwindow_dz, null);
//更改背景颜色透明
setBackgroundAlpha(VipRZActivity.this, 1f);
mPopupWindow = new PopupWindow(inflate);
//必须设置宽和高
mPopupWindow.setWidth(540);
mPopupWindow.setHeight(RelativeLayout.LayoutParams.WRAP_CONTENT);
//点击其他地方隐藏,false为无反应
mPopupWindow.setFocusable(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
//对他进行偏移
mPopupWindow.showAsDropDown(view, 0, 0, Gravity.BOTTOM);
}
mDzrecy = inflate.findViewById(R.id.pop_dzrecy);
//内容显示操作
//对popupWindow进行显示
mPopupWindow.update();
}
//设置屏幕背景透明效果
public static void setBackgroundAlpha(Activity activity, float alpha) {
WindowManager.LayoutParams lp = activity.getWindow().getAttributes();
lp.alpha = alpha;
activity.getWindow().setAttributes(lp);
}