如何在android中设置布局背景透明显示弹出窗口?

时间:2014-11-11 05:35:21

标签: android layout popupwindow

当我显示弹出窗口时,我希望能够模糊或调暗布局背景。就像这样。请帮助我。

这是我的代码:

LayoutInflater inflater = (LayoutInflater) ResidentActivity.this
                            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                    View layout = inflater.inflate(
                            R.layout.activity_appselection,
                            (ViewGroup) findViewById(R.id.popuplayoutelement));
                    pwindo = new PopupWindow(layout, 470, 540, true);
                    pwindo.showAtLocation(layout, Gravity.CENTER, 0, 45);

我的输出显示了这个

enter image description here 但我需要这样的 enter image description here

1 个答案:

答案 0 :(得分:3)

在布局中声明主要父级,例如:

RelativeLayout rl = (RelativeLayout)findViewById(R.id.relativeLayout);

然后当您显示弹出窗口时,也要添加此语句。

rl.setAlpha(0.5F);

这会将布局中的alpha设置为50%。您可以根据需要进行调整。