自定义Dialog设置大小

        显示dialog的大小设置

        WindowManager windowManager = mActivity.getWindowManager();
        Display d = windowManager.getDefaultDisplay(); // get the window's width and height
        WindowManager.LayoutParams p = getWindow().getAttributes(); //get the current dialog attributes
        p.height = (int) (d.getHeight() * 0.9); // set height as the window's 0.9
        p.width = (int) (d.getWidth() * 0.75); //  set width as the window's 0.75
        getWindow().setAttributes(p);

 

 

说明:这段代码必须写在oncreate方法setcontentview之后,在构造方法中写也没有效果。如果有调用requestWindowFeature(Window.FEATURE_NO_TITLE);
这句代码必须放在dialog的onCreate方法 setContentView 之前,否则会报错:AndroidRuntimeException: requestFeature() must be called before adding content

你可能感兴趣的:(android开发)