Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Full screen DialogFragment

Tags:

I am trying to create a DialogFragment with a width of MATCH_PARENT so the dialog is nearly full screen (leaving the padding around the edges for the floating look). I have seen this solution Full Screen DialogFragment in Android but am trying to avoid the hack of setting the width to 1000dp. With my current layout, whether I use FILL_PARENT or MATCH_PARENT it seems to be setting the width and height to WRAP_CONTENT.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

I have used this solution for Dialog (not DialogFragment) and it works as expected:

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
like image 700
invertigo Avatar asked Aug 09 '12 15:08

invertigo


1 Answers

this is perfect for me. when extends DialogFragment override onCreateView()... impelments all logic

dialog make it Full Screen just override this method

 @Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {

    // the content
    final RelativeLayout root = new RelativeLayout(getActivity());
    root.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));

    // creating the fullscreen dialog
    final Dialog dialog = new Dialog(getActivity());
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(root);
    dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.YELLOW));
    dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);

    return dialog;
}
like image 79
Attif Avatar answered Sep 24 '22 13:09

Attif