android window弹出窗

 Dialog myDialog = new Dialog(MainActivity.this, R.style.Translucent_NoTitle);
        View view = LayoutInflater.from(MainActivity.this).inflate(
                R.layout.dialog, null);
        myDialog.setContentView(view);
        myDialog.setCanceledOnTouchOutside(true);
        Window dialogWindow = myDialog.getWindow();
        dialogWindow.setGravity(Gravity.CENTER);
        //获取屏幕的宽高
        WindowManager wm = this.getWindowManager();
        int width = wm.getDefaultDisplay().getWidth();
        int height = wm.getDefaultDisplay().getHeight();
        //设置弹出框的大小
        dialogWindow.setLayout(width*5/6,height/3);
        //展示弹出
        myDialog.show();

    

你可能感兴趣的:(android window弹出窗)