Android简单实现PopupWindow全局弹出

        //设置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);

 

你可能感兴趣的:(Android简单实现PopupWindow全局弹出)