設定popWindow出現時,背景後面變暗
阿新 • • 發佈:2019-02-07
if (null == changePopupWindow) {
LayoutInflater inflater = LayoutInflater.from(this);
View popWindow = inflater.inflate(R.layout.pop_custm_recept_arreas,
null);
arreasGroup = (RadioGroup) popWindow
.findViewById(R.id.pop_arreas_group);
arreasGroup.setOnCheckedChangeListener(this );
changePopupWindow = new PopupWindow(popWindow,
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
// 設定popwindow可觸控
changePopupWindow.setFocusable(false);
// 設定pop外的區域是否可觸控
changePopupWindow.setOutsideTouchable(true );
// 例項化一個ColorDrawable顏色為半透明
ColorDrawable dw = new ColorDrawable(0xb0000000);
// 設定pop彈出窗體的背景
changePopupWindow.setBackgroundDrawable(dw);
backgroundAlpaha(CustomerReceptDestActivity.this, 0.5f);
// 設定popWindow的顯示和消失動畫
changePopupWindow.setAnimationStyle(R.style.mypopup_anim_style);
// 當點選取消的時候,pw消失
popWindow.findViewById(R.id.pop_custom_pay_cancel_submit)
.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
changePopupWindow.dismiss();
}
});
changePopupWindow.setOnDismissListener(new OnDismissListener() {
@Override
public void onDismiss() {
backgroundAlpaha(CustomerReceptDestActivity.this, 1.0f);
}
});
}
ColorDrawable dw = new ColorDrawable(0xb0000000);
changePopupWindow.setBackgroundDrawable(dw);
backgroundAlpaha(CustomerReceptDestActivity.this, 0.5f);
changePopupWindow.showAtLocation(mainLayout, Gravity.CENTER, 0, 0);
}
/**
* 設定新增螢幕的背景透明度
* **/
public void backgroundAlpaha(Activity context, float bgAlpha) {
WindowManager.LayoutParams lp = context.getWindow().getAttributes();
lp.alpha = bgAlpha;
context.getWindow()
.addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
context.getWindow().setAttributes(lp);
}