Android dialog width

后端 未结 6 1862
天涯浪人
天涯浪人 2020-12-02 15:16

I can\'t seem to control the dialog width. I have a simple layout like so`




        
6条回答
  •  时光说笑
    2020-12-02 15:55

    Try this. It works for me.

        dialog = new Dialog(Activity.this);
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        dialog.setContentView(R.layout.feedback_popup);
        dialog.setCancelable(false);
        dialog.setCanceledOnTouchOutside(false);
    
        WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
        lp.copyFrom(dialog.getWindow().getAttributes());
        lp.width = WindowManager.LayoutParams.MATCH_PARENT;
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        lp.gravity = Gravity.CENTER;
    
        dialog.getWindow().setAttributes(lp);
    

提交回复
热议问题