Android中DialogFragment全屏的方式

对于普通的Dialog或者AlertDialog,都可以用layout设定match_parent,但是DialogFragment似乎需要代码才能搞定,如下:

@Override
    public void onStart() {
        super.onStart();
        Dialog dialog = getDialog();
        if (dialog != null) {
            int width = ViewGroup.LayoutParams.MATCH_PARENT;
            int height = ViewGroup.LayoutParams.MATCH_PARENT;
            dialog.getWindow().setLayout(width, height);
        }
    }

 

Leave a Reply

Your email address will not be published. Required fields are marked *