10

我想为全屏创建一个弹出窗口

我使用了以下内容:

LayoutInflater inflater = (LayoutInflater) MainActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

layoutt = inflater.inflate(R.layout.loginto,(ViewGroup) findViewById(R.id.window1));

pwindow = new PopupWindow(layoutt,LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,true);

这涵盖了操作栏但不包括全屏..

api 11+ 也支持 LayuotParams.WRAP_CONTENT 。我需要从 api 8 级开始工作的解决方案。

4

2 回答 2

14

对于全屏,您必须传递MATCH_PARENT参数而不是WRAP_CONTENT

pwindow = new PopupWindow(layout,LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT,true);
于 2014-06-28T12:39:49.780 回答
1

JAVA版

 View view=getLayoutInflater().inflate(R.layout.dialog_complete_pause_work,null,false);

 PopupWindow popupWindow=new PopupWindow(view, ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT);

 popupWindow.showAtLocation(view, Gravity.CENTER,0,0);

科特林版本:

val view = layoutInflater.inflate(R.layout.your_layout, null, false)

val popupWindow = PopupWindow(view, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)

popupWindow.showAtLocation(view, Gravity.CENTER, 0, 0)
于 2018-07-03T07:19:28.087 回答