//设置contentView
View contentView = LayoutInflater.from(MainActivity.this).inflate(R.layout.activity_main_dialog, null);
PopupWindow popupWindow = new PopupWindow(contentView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
popupWindow.setContentView(contentView);
//点窗口外关闭
popupWindow.setBackgroundDrawable(new BitmapDrawable());
popupWindow.setFocusable(true);
//全局弹出
popupWindow.setWindowLayoutType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
//显示位置
popupWindow.showAtLocation(getWindow().getDecorView(),Gravity.CENTER,0,0);