How to make DialogFragment width to Fill_Parent

前端 未结 18 2528
栀梦
栀梦 2020-12-04 08:21

I am working on an android application where I am using DialogFragment to display the dialog but its width is very small. How I can make this width to fil

18条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-04 09:12

    use this in onCreateView method of DialogFragment

        Display display = getActivity().getWindowManager().getDefaultDisplay();
        int width = display.getWidth();
        int px = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, **220**, getResources().getDisplayMetrics());
        getDialog().getWindow().setLayout(width,px);
    

    220 is dialog fragment height, change it as u wish

提交回复
热议问题