popupWindow的使用

private void initQiandao() {

View popupview = LayoutInflater.from(this).inflate(R.layout.quandaozmglayout, null);

popupWindow1 = new PopupWindow(this);

popupWindow1.setContentView(popupview);

popupWindow1.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);//自适应高度

popupWindow1.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);//自适应高度

popupWindow1.setAnimationStyle(R.style.mypopupstyle);//动画

popupWindow1.setBackgroundDrawable(new BitmapDrawable());

popupWindow1.setFocusable(true);

popupWindow1.showAtLocation(qiandaolayout, Gravity.CENTER, 0, 0);

bgAlpha(0.5f);//半透明背景

popupWindow1.setOutsideTouchable(true);

popupWindow1.setBackgroundDrawable(new ColorDrawable(Color.BLUE));

popupWindow1.setOnDismissListener(new PopupWindow.OnDismissListener() {

@Override

public void onDismiss() {

bgAlpha(1f);//白色背景

}

});

}

点击关闭背景还原

private void bgAlpha(float alpha) {

WindowManager.LayoutParams lp = (QianDaosmgActivity.this.getWindow()).getAttributes();

lp.alpha = alpha;// 0.0-1.0

(QianDaosmgActivity.this.getWindow()).setAttributes(lp);

}


动画