777e6317467d938c251346a35750bded.png

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);

}

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐