Android弹出窗口全屏
我想创建一个全屏弹出窗口 我使用了以下方法:Android弹出窗口全屏,android,popupwindow,android-fullscreen,Android,Popupwindow,Android Fullscreen,我想创建一个全屏弹出窗口 我使用了以下方法: LayoutInflater inflater = (LayoutInflater) MainActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); layoutt = inflater.inflate(R.layout.loginto,(ViewGroup) findViewById(R.id.window1)); pwindow = new PopupWindow(la
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_内容。我需要解决方案从api级别8开始工作。对于全屏,您必须传递
MATCH\u PARENT
参数,而不是WRAP\u CONTENT
pwindow = new PopupWindow(layout,LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT,true);
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);
Kotlin版本:
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)
这个警告需要考虑吗?该字段要求API级别为11(当前最低为8):android.app.ActionBar.LayoutParams#FILL_PARENT@mkumar这只是个警告,所以根本不用担心。你可以选择
FILL\u PARENT
或MATCH\u PARENT
你喜欢的任何东西……)这是不推荐使用的,任何其他方法?FILL\u PARENT
在早期的API中被重命名为MATCH\u PARENT
,因此只需使用后者,一切都会很好。在Kotlin中,我建议尽可能使用“val”——正如官方建议中所述。在本例中,如果您知道“popupWindow”将是popupWindow类的有效实例,则无需将其定义为变量,该变量将是可为null的类型。对于“val”,它总是被赋值的,因此您甚至不需要“?”操作符来检查空值。在这种情况下,您不需要“?”来检查popupWindow是否为空。可以直接访问:)