popupWindow=new PopupWindow(MainActivity.this);
View popupView=getLayoutInflater().inflate(R.layout.selectedpopupwindow, null);
popupWindow.setContentView(popupView);
popupWindow.setWidth(LayoutParams.MATCH_PARENT);
popupWindow.setHeight(LayoutParams.MATCH_PARENT);
popupWindow.setBackgroundDrawable(new BitmapDrawable());
setBackgroundDrawable如果不设置这个弹出框会有点上移的感觉,
这里可以设置new BitmapDrawable(),也可以new ColorDrawable(),也可以直接null,就都不会有问题了,不知道具体是什么意思
popupWindow.setOutsideTouchable(true);
打开popupWindow.showAtPosition(XX,XX,X,X);
关闭popupWindow: popupWindow.dismiss();
本文介绍了如何在Android应用中创建PopupWindow,并详细说明了如何通过设置ContentView、宽度、高度及背景来定制其外观。此外,还解释了设置背景Drawable的重要性,确保弹窗稳定显示。
422

被折叠的 条评论
为什么被折叠?



