1、第一步写出你要显示的内容(单独的xml)
2、显示和关闭显示(代码已有注释)
//在这里绑定你要显示的内容布局
View viewPop = getLayoutInflater().inflate(R.layout.item_zero_buy_problem, null);
//实例化创建PopupWindow()
//参数(窗体的视图,宽,高)
int height = getWindowManager().getDefaultDisplay().getWidth();
PopupWindow popup = new PopupWindow(viewPop, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
//背景颜色
//设置弹出窗口的动画样式
popup.setAnimationStyle(android.R.style.Animation_Dialog);
popup.setBackgroundDrawable(getResources().getDrawable(android.R.drawable.alert_dark_frame));
//设置背景透明色
popup.getBackground().setAlpha(5);
//设置点击边上可以消失
popup.setOutsideTouchable(true);
//设置是否可以获取焦点
popup.setFocusable(true);
//设置是否可以触摸
popup.setTouchable(true);
//设置软件盘
popup.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
//开始显示show 位置的设置
//activity显示
//View view= LayoutInflater.from(MainActivity.this).inflate(R.layout.main, null);
//popup.showAtLocation(view, Gravity.CENTER, 0, 0);
//Fragment显示
popup.showAtLocation(getView(), Gravity.CENTER, 0, 0);
//绑定按钮和监听点击事件
Button bt_ikonw = viewPop.findViewById(R.id.bt_ikonw);
bt_ikonw.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
popup.dismiss();
}
});
如果博文对你有启发作用,请为博主点个赞,谢谢!!!