实现思路:1、获取到根view 2、获取到要弹出的view 3、确定位置并弹出(同时背景变暗)4、触摸弹框外弹框消失,背景恢复
//获取根view
mRootView=LayoutInflater.from(EditCameraActivity.this).inflate(R.layout.activity_edit_camera, null);
//获取弹出view
mPopView=LayoutInflater.from(EditCameraActivity.this).inflate(R.layout.popupwindow,null);
//创建PopupWindow
mPopupWindow = new PopupWindow(mPopView,
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT,true);
//设置触摸背景时使弹出框消失
mPopupWindow.setOutsideTouchable(true);
//设置弹出框内部控件可点击
mPopupWindow.setFocusable(true);
//弹出框消失时,背景不再灰暗
mCommitPopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
@Override
public void onDismiss() {
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.alpha = 1f;
getWindow().setAttributes(lp);
}
});
//更改弹出时背景的透明度
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.alpha = 0.4f;
getWindow().setAttributes(lp);
//确定弹出的位置并弹出
mPopupWindow.showAtLocation(mRootView, Gravity.BOTTOM,0,0);