How to get dialog size?

前端 未结 4 648
情书的邮戳
情书的邮戳 2020-12-20 12:58

I am looking for a way to get size of a custom dialog. I went through this question, but the only answer given is pretty useless, because if I try mDialog.getWindow().

4条回答
  •  暖寄归人
    2020-12-20 13:42

    In case, if you have your own XML layouts for custom dialog.

    
    
    
        /* whatever you want here */
    
    
    

    In activity:

        final Dialog dialog = new Dialog(this);
        dialog.setContentView(R.layout.popup_gameover);
    
        dialog.setOnShowListener(new DialogInterface.OnShowListener() {
            @Override
            public void onShow(DialogInterface d) {
                View view = dialog.findViewById(R.id.dialog_main_layout);
                int width = view.getWidth();
                int height = view.getHeight();
    
                ...
            }
        });
    

    This width and height exacly as expected.

提交回复
热议问题