How to make DialogFragment width to Fill_Parent

前端 未结 18 2530
栀梦
栀梦 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 08:56

    I want clarify this. Both the ways are right, But with different DialogFragment.

    Using android.app.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);
        }
    }
    

    Using android.support.v4.app.DialogFragment

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setStyle(DialogFragment.STYLE_NORMAL, android.R.style.Theme_Black_NoTitleBar_Fullscreen);
    }
    

提交回复
热议问题