Is there any way to make my Dialog view full screen, i.e dialog occupy the entire screen (like an Activity). I tried using the LayoutParams and styles like
Here are steps how to create a full screen dialog with custom layout which occupies the entire screen without any padding from each site.
Step 1: Define your custom dialog layout named layout_fullscreen_dialog.xml
Step 2: Define a new style in styles.xml
named FullScreenDialog
Step 3: Write a method which creates and shows a dialog
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
createAndShowDialog(this);
}
// This method used to create and show a full screen dialog with custom layout.
public void createAndShowDialog(Context context) {
Dialog dialog = new Dialog(context, R.style.FullScreenDialog);
dialog.setContentView(R.layout.layout_fullscreen_dialog);
WindowManager.LayoutParams layoutParams = dialog.getWindow().getAttributes();
dialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
dialog.getWindow().setAttributes(layoutParams);
dialog.show();
}
}