Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make material design full screen dialog?

I have tried many variants to create full screen dialog but I couldn't. I need something, like this, with two buttons:

image

like image 204
Alex.Marynovskyi Avatar asked Aug 14 '15 19:08

Alex.Marynovskyi


1 Answers

If you really want a a fullscreen dialog just extend the Dialog class and add a few tweaks. (You can also accomplish this without extending anything, but I thought you might want to keep everything in one place)

In your constructor you need to set the style (for your material look, or it can be an empty style tag):

super(context, R.style.DialogStyle);

you also need to set the view: (This is where you would define where/what those two buttons are)

setContentView(R.layout.dialog_view);

Finally, you might also need to modify the windows layout parameters:

getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);

I have found on the devices I have tested that setting the style is the most important.

*EDIT*

To make it a little more clear you have two options:

public class MyDialog extends Dialog {

    public MyDialog(Context context) {
        super(context, R.style.YourStyle);
        setContentView(R.layout.dialog_view);
        getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT); //Optional
        //Any other code you want in your constructor
    }
}

Then when you want to show it:

//Inside your activity
MyDialog dialog = new MyDialog(this); //Assuming you are in an activity 'this' is your context
dialog.show();

Or you can just do this:

Dialog normalDialog = new Dialog(this, R.style.YourStyle);
normalDialog.setContentView(R.layout.dialog_view);
normalDialog.show();
like image 152
Luke Cauthen Avatar answered Oct 04 '22 01:10

Luke Cauthen