204

I'm trying to show an almost fullscreen DialogFragment. But I'm somehow not able to do so.

The way I am showing the Fragment is straight from the android developer documentation

FragmentManager f = ((Activity)getContext()).getFragmentManager();
FragmentTransaction ft = f.beginTransaction();
Fragment prev = f.findFragmentByTag("dialog");
if (prev != null) {
    ft.remove(prev);
}
ft.addToBackStack(null);

// Create and show the dialog.
DialogFragment newFragment = new DetailsDialogFragment();
newFragment.show(ft, "dialog");

I know naively tried to set the RelativeLayout in the fragment to fill_parent and some minWidth and minHeight.

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"  
    android:minWidth="1000px" 
    android:minHeight="600px"
    android:background="#ff0000">

I would know expect the DialogFragment to fill the majority of the screen. But I only seems to resize vertically but only until some fixed width horizontally.

I also tried to set the Window Attributes in code, as suggested here: http://groups.google.com/group/android-developers/browse_thread/thread/f0bb813f643604ec. But this didn't help either.

I am probably misunderstanding something about how Android handles Dialogs, as I am brand new to it. How can I do something like this? Are there any alternative ways to reach my goal?


Android Device:
Asus EeePad Transformer
Android 3.0.1


Update: I now managed to get it into full screen, with the following code in the fragment

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setStyle(STYLE_NO_FRAME, android.R.style.Theme_Holo_Light);
}

Unfortunately, this is not quite want I want. I definitely need a small "padding" around the dialog to show the background.

Any ideas how to accomplish that?

Jonik
  • 80,077
  • 70
  • 264
  • 372
Eric
  • 2,053
  • 2
  • 13
  • 6

31 Answers31

237

To get DialogFragment on full screen

Override onStart of your DialogFragment like this:

@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);
    }
}

And thanks very much to this post: The-mystery-of-androids-full-screen-dialog-fragments

David
  • 37,109
  • 32
  • 120
  • 141
  • 10
    Exactly this works, but i tried with Videoview and it doesnt works for that. StatusBar still shows. So this fixed me below code: dialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); – WhiteHorse Sep 02 '15 at 19:23
  • 1
    finally sort out, thansk for suggestion @David – Ashu Kumar Jan 08 '16 at 05:56
  • 1
    This worked nicely for me. I used `ViewGroup.LayoutParams.WRAP_CONTENT` for the height. Thanks. – dazed Jan 13 '16 at 19:39
  • 1
    this is clean and non-hacky – rommex Oct 29 '17 at 08:23
  • 11
    this is not working for my case.. it showing some padding from all corners. any help? – Abdul Waheed Nov 23 '17 at 10:45
  • Yep, also shows some weird margins on mine and completely ignores the margin I set manually on the fragment's root view, which I really need to control manually. – Felipe Ribeiro R. Magalhaes Feb 10 '20 at 22:41
  • 3
    for me, it showed margins horizontally, but adding the following lines in `onCreateDialog` method solved my problem `final Dialog dialog = new Dialog(requireContext()); dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));` – nikhil123 Jun 23 '20 at 11:23
  • @AbdulWaheed You need to also set a style adjusting `windowNoTitle`, `windowFullscreen`, and `windowIsFloating` in the DialogFragment's `onCreate` – welshk91 Oct 03 '20 at 22:07
  • Regarding the margins people face, in continuation to what nikhil123 suggested, you can also just set the background to white instead of transparent and it will also get rid of the margins. – Itay Feldman Jan 19 '21 at 23:49
  • It works, save my day! – thecr0w Jul 19 '23 at 08:39
172
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setStyle(DialogFragment.STYLE_NORMAL,
             android.R.style.Theme_Black_NoTitleBar_Fullscreen);
}
Nolan Amy
  • 10,785
  • 5
  • 34
  • 45
Chirag Nagariya
  • 1,864
  • 1
  • 11
  • 6
  • 7
    The only solution that seemed to work for me. Others were sometimes working, sometimes not. Let's hope I don't find an exception to this one too :) – azertiti Mar 22 '13 at 12:25
  • 15
    This works for me too.While if you want the background to be transparent,you should use '''android.R.style.Theme_Translucent_NoTitleBar''' – Kevin May 27 '14 at 03:33
  • This way should be an accept answer. No hack, cheat. All others don't work for me. – ductran Jan 14 '16 at 06:31
  • 4
    The key is passing STYLE_NORMAL. This makes the dialog to fill screen just like any other activity. We can use any theme. For material design, you can derive a material theme (e.g. Theme.AppCompat.NoActionBar which keeps system decor but removes action bar). – rpattabi Apr 28 '16 at 07:05
  • 2
    Ha-ha, when I launched, a black screen appeared and I thought it had been freezed. Then I changed a theme to Theme_Light_NoTitleBar_Fullscreen. Thanks, a dialog occupies a whole screen (including a statusbar). – CoolMind Apr 29 '16 at 10:22
  • 2
    Theme_DeviceDefault_Light_NoActionBar_Fullscreen fow dialog with white background. – Hitesh Sahu Jun 08 '17 at 11:34
  • It works but then the margins of the fragment's parent layout (root) are not being respected anymore. I want these margins to be respected so the content bellow the dialog can still be seen, but this completely removes the margins! I Want the margins defined in the XML layout to be respected. Any ideas? – Felipe Ribeiro R. Magalhaes Feb 10 '20 at 22:33
  • use DialogFragment.STYLE_NO_FRAME to remove margins. Worked for me. – Dinith Rukshan Kumara Jul 18 '22 at 18:21
72

Try switching to a LinearLayout instead of RelativeLayout. I was targeting the 3.0 Honeycomb api when testing.

public class FragmentDialog extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Button button = (Button) findViewById(R.id.show);
    button.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            showDialog();
        }
    });
}

@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
}

void showDialog() {
    FragmentTransaction ft = getFragmentManager().beginTransaction();
    DialogFragment newFragment = MyDialogFragment.newInstance();
    newFragment.show(ft, "dialog");
}

public static class MyDialogFragment extends DialogFragment {

    static MyDialogFragment newInstance() {
        MyDialogFragment f = new MyDialogFragment();
        return f;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.fragment_dialog, container, false);
        return v;
    }

}
}

and the layouts: fragment_dialog.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:minWidth="1000dp"  
    android:minHeight="1000dp"> 
 </LinearLayout> 

main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"
    android:background="#ffffff">
    <Button android:id="@+id/show"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:layout_weight="0"
        android:text="show">
    </Button>
</LinearLayout>
Kapil Rajput
  • 11,429
  • 9
  • 50
  • 65
bradley4
  • 3,823
  • 6
  • 34
  • 41
  • And for me, I needed to use a RelativeLayout, but the dialog width wasn't adjusting properly to the contents, so I nested the RelativeLayout in a LinearLayout whose only child was the RelativeLayout... this triggered the proper width adjustments. – Peter Ajtai Dec 25 '11 at 01:56
  • 1
    I tested everything, but I can confirm the only thing that worked for my DialogFragment was wrapping my whole layout in a LinearLayout. That way I could set width and height of my (now wrapped) original layout...wasted hours on this – Till - Appviewer.io Jul 23 '12 at 11:18
  • 7
    Setting minWidth and minHeight to be somehing large seems to be the crucial part; but this is a hack instead of a clean solution. The answer given by @David below - explained further in the link he gives - also works and is clean. – Gerrit Begher Oct 28 '14 at 18:18
  • @tir38 I don't think that's true because onCreateDialog() already has an implementation in the superclass. – starkej2 Nov 18 '15 at 13:11
  • This should be the accepted answer. Elaborate and clear – mutiemule May 08 '19 at 14:14
  • That is so weird...switching it fixed the issue. – DIRTY DAVE May 11 '20 at 05:23
70

Make a Full screen DialogFragment by using only the style

First solution

1. Add to your style.xml:

    <style name="FullScreenDialog" parent="Theme.AppCompat.Light.Dialog">
        <item name="android:backgroundDimEnabled">false</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:padding">0dp</item>
        <item name="android:windowIsFloating">false</item>
        <item name="android:windowBackground">@android:color/transparent</item>
        <item name="android:windowCloseOnTouchOutside">false</item>
    </style>

2. Add to your DialogFragment:

@Override
public int getTheme() {
    return R.style.FullScreenDialog;
}

Alternative solution

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)

    setStyle(DialogFragment.STYLE_NO_FRAME, R.style.FullScreenDialog)
}
victor.hernandez
  • 2,462
  • 2
  • 27
  • 32
vovahost
  • 34,185
  • 17
  • 113
  • 116
51

According to this link DialogFragment fullscreen shows padding on sides this will work like a charm.

@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.TRANSPARENT));
    dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);

    return dialog;
}
Community
  • 1
  • 1
Ayman Mahgoub
  • 4,152
  • 1
  • 30
  • 27
19

In my case I used the following approach:

    @Override
    public void onStart() {
        super.onStart();
        getDialog().getWindow().setLayout(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    }
}

Plus LinearLayout to fill all the space with content.

But there were still small gaps between left and right edges of the dialog and the screen edges on some Lollipop+ devices (e.g. Nexus 9).

It was not obvious but finally I figured out that to make it full width across all the devices and platforms window background should be specified inside styles.xml like the following:

<style name="Dialog.NoTitle" parent="Theme.AppCompat.Dialog">
    <item name="android:windowNoTitle">true</item>
    <item name="android:padding">0dp</item>
    <item name="android:windowBackground">@color/window_bg</item>
</style>

And of course this style needs to be used when we create the dialog like the following:

    public static DialogFragment createNoTitleDlg() {
        DialogFragment frag = new Some_Dialog_Frag();
        frag.setStyle(DialogFragment.STYLE_NO_TITLE, R.style.Dialog_NoTitle);
        return frag;
}
goRGon
  • 4,402
  • 2
  • 43
  • 45
  • This is the answer. Works great. – VonSchnauzer Nov 28 '16 at 10:06
  • 2
    I tried most of the answers on this thread, some worked, but I lost all my app compat theme styles. I hoped this one would work as parent theme was AppCompat. It _almost_ worked. For me, I had to add 2 additional styles: `true false` Source: [TechRepublic](http://www.techrepublic.com/article/pro-tip-unravel-the-mystery-of-androids-full-screen-dialog-fragments/) – Breeno Apr 11 '17 at 17:08
16

I met the issue before when using a fullscreen dialogFragment: there is always a padding while having set fullscreen. try this code in dialogFragment's onActivityCreated() method:

public void onActivityCreated(Bundle savedInstanceState)
{   
    super.onActivityCreated(savedInstanceState);
    Window window = getDialog().getWindow();
    LayoutParams attributes = window.getAttributes();
    //must setBackgroundDrawable(TRANSPARENT) in onActivityCreated()
    window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    if (needFullScreen)
    {
        window.setLayout(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    }
}
dabluck
  • 1,641
  • 2
  • 13
  • 20
ruidge
  • 1,149
  • 1
  • 15
  • 14
16

And the kotlin version!

override fun onStart() {
    super.onStart()
    dialog?.let {
        val width = ViewGroup.LayoutParams.MATCH_PARENT
        val height = ViewGroup.LayoutParams.MATCH_PARENT
        it.window?.setLayout(width, height)
    }
}
Boldijar Paul
  • 5,405
  • 9
  • 46
  • 94
13

As far as the Android API got updated, the suggested method to show a full screen dialog is the following:

FragmentTransaction transaction = this.mFragmentManager.beginTransaction();
// For a little polish, specify a transition animation
transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
// To make it fullscreen, use the 'content' root view as the container
// for the fragment, which is always the root view for the activity
transaction.add(android.R.id.content, this.mFragmentToShow).commit();

otherwise, if you don't want it to be shown fullscreen you can do this way:

this.mFragmentToShow.show(this.mFragmentManager, LOGTAG);

Hope it helps.

EDIT

Be aware that the solution I gave works but has got a weakness that sometimes could be troublesome. Adding the DialogFragment to the android.R.id.content container won't allow you to handle the DialogFragment#setCancelable() feature correctly and could lead to unexpected behaviors when adding the DialogFragment itself to the back stack as well.

So I'd suggested you to simple change the style of your DialogFragment in the onCreate method as follow:

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

Hope it helps.

andrea.rinaldi
  • 1,167
  • 1
  • 13
  • 33
  • 1
    I agree. Here's a full explanation from the Android Developer guide: [link](http://developer.android.com/guide/topics/ui/dialogs.html#FullscreenDialog) – user2274431 May 21 '15 at 08:09
12

Try to use setStyle() in onCreate and override onCreateDialog make dialog without title

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

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Dialog dialog = super.onCreateDialog(savedInstanceState);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);        
    return dialog;
}

or just override onCreate() and setStyle fellow the code.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);    
    setStyle(DialogFragment.STYLE_NO_TITLE, android.R.style.Theme);        
}
Jay Parker
  • 631
  • 11
  • 23
9

It can indeed depends on how the layout is defined. But to ensure that the dialog gets the required size, the best solution is to provide the LayoutParams once the dialog is shown (and not on creation). On a DialogFragment the dialog is shown on the onStart method, so a valid method to get full width is:

@Override public void onStart() {
    super.onStart();
    Dialog d = getDialog();
    if (d!=null){
        d.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    }
}

To also provide a theme, or style, like a NO_TITLE style, the best location is on the onCreate method:

@Override public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setStyle(STYLE_NO_TITLE, android.R.style.Theme_Holo_Light_Dialog);
}
coderazzi
  • 430
  • 6
  • 8
8

Note : Even one can find right answer here. But I want clarify a confusion.

Use below code for 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);
    }
}

Use below code for 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);
}
Khemraj Sharma
  • 57,232
  • 27
  • 203
  • 212
7

The easiest way to do achieve this is :

Add the following theme to your styles.xml

<style name="DialogTheme" parent="AppTheme">
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowFullscreen">false</item>
    <item name="android:windowIsFloating">false</item>
</style>

and in your class extending DialogFragment, override

@Override
public int getTheme() {
    return R.style.DialogTheme;
}

This will work on Android OS 11(R) as well.

https://anubhav-arora.medium.com/android-full-screen-dialogfragment-1410dbd96d37

Anubhav
  • 1,984
  • 22
  • 17
4

This is the solution how I figured out this issue:

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Dialog dialog = super.onCreateDialog(savedInstanceState);    
    dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);   

    return dialog;
}

@Override
public void onStart() {
    super.onStart();
    Dialog dialog = getDialog();
    if (dialog != null) {
            dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
            dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    }
}
savepopulation
  • 11,736
  • 4
  • 55
  • 80
3

Create below theme in your style.xml:

<style name="DialogTheme" parent="Theme.AppCompat.Light.DarkActionBar">
   <item name="android:paddingRight">0dp</item>
   <item name="android:paddingLeft">0dp</item>
   <item name="android:layout_width">match_parent</item>
   <item name="android:windowNoTitle">true</item>
</style>

then set the style in DialogFragment

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NO_TITLE, R.style.DialogTheme);
}
Zahra.HY
  • 1,684
  • 1
  • 15
  • 25
2

Chirag Nagariya is right except the '_Fullscreen' addition. it can be solved using any base style which not derived from Dialog style. 'android.R.style.Theme_Black_NoTitleBar' can be used as well.

Shoham Ben-Har
  • 317
  • 1
  • 4
  • 16
2

The following way will work even if you are working on a relative layout. Follow the following steps:

  1. Go to theme editor ( Available under Tools-> Android -> Theme Editor)
  2. Select show all themes. Select the one with AppCompat.Dialog
  3. Choose the option android window background if you want it to be of any specific colored background or a transparent one.
  4. Select the color and hit OK.Select a name of the new theme.
  5. Go to styles.xml and then under the theme just added, add these two attributes:

    <item name="android:windowNoTitle">true</item>
    <item name="android:windowIsFloating">false</item>
    

My theme setting for the dialog is as under:

<style name="DialogTheme" parent="Theme.AppCompat.Dialog" >
    <item name="android:layout_width">match_parent</item>
    <item name="android:layout_height">match_parent</item>
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowIsFloating">false</item>

Make sure that the theme has a parent as Theme.AppCompat.Dialog Another way would be just make a new style in styles.xml and change it as per the code above.

  1. Go to your Dialog Fragment class and in the onCreate() method, set the style of your Dialog as:

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

Saumya Mehta
  • 181
  • 1
  • 1
  • 10
1
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Dialog dialog = new Dialog(getActivity(), android.R.style.Theme_Holo_Light);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);

    return dialog;
}

This solution applies a full screen theme on the dialog, which is similar to Chirag's setStyle in onCreate. A disadvantage is that savedInstanceState is not used.

Alpha Huang
  • 1,297
  • 1
  • 12
  • 15
1

Try this for common fragment dialog for multiple uses. Hope this will help you bettor

public class DialogFragment extends DialogFragment {

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_visit_history_main, container, false);

        getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
        getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        initializeUI(rootView);
        return rootView;
    }

    @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);
        }
    }
    private void initializeUI(View rootView) {
    //getChildFragmentManager().beginTransaction().replace(R.id.fv_container,FragmentVisitHistory.getInstance(), AppConstant.FRAGMENT_VISIT_HISTORY).commit();
    }
}
Paolo Forgia
  • 6,572
  • 8
  • 46
  • 58
Dashrath Rathod
  • 508
  • 1
  • 5
  • 15
  • please refer to this question - https://stackoverflow.com/questions/45494644/how-to-set-the-height-of-the-dialog-fragment-accurately-in-android – Aman Verma Aug 04 '17 at 20:56
1

This is what you need to set to fragment:

/* theme is optional, I am using leanback... */
setStyle(STYLE_NORMAL, R.style.AppTheme_Leanback);

In your case:

DialogFragment newFragment = new DetailsDialogFragment();
newFragment.setStyle(STYLE_NORMAL, R.style.AppTheme_Leanback);
newFragment.show(ft, "dialog");

And why? Because DialogFragment (when not told explicitly), will use its inner styles that will wrap your custom layout in it (no fullscreen, etc.).

And layout? No hacky way needed, this is working just fine:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
    ...
</RelativeLayout>

Enjoy

arenaq
  • 2,304
  • 2
  • 24
  • 31
1

I am very late for answering this question still i want to share this answer so that in future anyone can use this.

I have used this code in my project it works in lower version as well as higher version.

Just use this theme inside onCreateDialog() like this :

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    View view = getActivity().getLayoutInflater().inflate(R.layout.dialog_pump_details, null);

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), android.R.style.Theme_Black_NoTitleBar_Fullscreen);
    return builder.create();
}

android.R.style.Theme_Black_NoTitleBar_Fullscreen - Here is the source code for this theme you can see only this theme is enough to make DialogFragment appear in full screen.

<!-- Variant of {@link #Theme_Black} that has no title bar and
     no status bar.  This theme
     sets {@link android.R.attr#windowFullscreen} to true.  -->
<style name="Theme.Black.NoTitleBar.Fullscreen">
    <item name="windowFullscreen">true</item>
    <item name="windowContentOverlay">@null</item>
</style>

Please let me know if anyone face any issue. Hope this is helpful. Thanks :)

Biswajit
  • 1,829
  • 1
  • 18
  • 33
1

Add this below lines in style of the full screen dialog.

<item name="android:windowNoTitle">true</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowIsFloating">false</item>
MEGHA DOBARIYA
  • 1,622
  • 9
  • 7
  • or : override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setStyle(DialogFragment.STYLE_NORMAL, R.style.BottomSheetDialogThemeNoFloating) – Filipkowicz Apr 06 '20 at 09:52
1

In case anyone else comes across this, I had a similar experience to this but it turns out that the issue was that I had forgotten to return the inflated view from onCreateView (instead returning the default super.onCreateView). I simply returned the correct inflated view and that solved the problem.

user1205577
  • 2,388
  • 9
  • 35
  • 47
0

window.setLayout isn't enough for older devices.

Here is what I do:

try {
    ViewGroup parent = (ViewGroup) view;
    do {
        parent = (ViewGroup) parent.getParent();
        if (parent == null)
            break;

        parent.getLayoutParams().height = ViewGroup.LayoutParams.MATCH_PARENT;
        parent.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT;
        parent.requestLayout();
    } while (true);
} catch (Exception e){}
palindrom
  • 18,033
  • 1
  • 21
  • 37
0
This below answer works for me in fragment dialog.  


  Dialog dialog = getDialog();
        if (dialog != null)
        {
            int width = ViewGroup.LayoutParams.MATCH_PARENT;
            int height = ViewGroup.LayoutParams.MATCH_PARENT;
            dialog.getWindow().setLayout(width, height);
        }
MEGHA DOBARIYA
  • 1,622
  • 9
  • 7
0

A solution by using the new ConstraintLayout is wrapping the ConstraintLayout in a LinearLayout with minHeight and minWidth fixed. Without the wrapping, ConstraintLayout is not getting the right size for the Dialog.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:minWidth="1000dp"
    android:minHeight="1000dp"
    android:orientation="vertical">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/background_color"
        android:orientation="vertical">
        <!-- some constrained views -->
    </androidx.constraintlayout.widget.ConstraintLayout>

</LinearLayout>
Nicola Gallazzi
  • 7,897
  • 6
  • 45
  • 64
0

Worked for me in Kotlin,

 override fun onActivityCreated(savedInstanceState: Bundle?) {
    super.onActivityCreated(savedInstanceState)

    dialog?.window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)

}
Aziz
  • 1,976
  • 20
  • 23
0

the following solution worked for me other solution gave me some space in the sides i.e not full screen

You need to make changes in onStart and onCreate method

@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);
    }
}


 public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
    final Dialog dialog = new Dialog(requireContext());
    dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
 }


   
nikhil123
  • 48
  • 1
  • 10
0

No more style that need more complex code.. with status bar..

public static void ShowFullScreenDialog(Context context, View contentView, string header)
        {

            using (Android.Support.V7.App.AlertDialog.Builder builder = new Android.Support.V7.App.AlertDialog.Builder(context, Android.Resource.Style.ThemeBlackNoTitleBarFullScreen))
            {
                var view = UIHelper.InflaterView(context, Resource.Layout.dialog_full_screen);
                builder.SetView(view);
                Dialog dialog = builder.Create();
                dialog.Window.SetBackgroundDrawableResource(ThemeHelper.GetMainActivityThemeDrawable());
                dialog.Window.SetLayout(context.Resources.DisplayMetrics.WidthPixels, context.Resources.DisplayMetrics.HeightPixels);
                dialog.Window.DecorView.SystemUiVisibility = StatusBarVisibility.Visible;
                
                //fullLinear
                var headtxt = view.FindViewById<TextView>(Resource.Id.headertxt);
                headtxt.SetTextColor(Color.White);
                headtxt.Text = header;
                var fullLinear = view.FindViewById<LinearLayout>(Resource.Id.fullLinear);
                var closeBttn = view.FindViewById<ImageButton>(Resource.Id.closeBttn);
                closeBttn.ImageTintList = ColorHelper.ConvertColorToStateList(Color.White);
                closeBttn.Click += delegate
                {
                    dialog.Hide();
                };
                if (contentView.Parent != null)
                    ((ViewGroup)contentView.Parent).RemoveView(contentView); // <- fix
                fullLinear.AddView(contentView);
                
                dialog.Show();
            }
            
        }

Important

dialog.Window.SetLayout(context.Resources.DisplayMetrics.WidthPixels, context.Resources.DisplayMetrics.HeightPixels);
Minute V
  • 25
  • 3
0
class NameDialog : DialogFragment(){
lateinit  var mDataBinding:NameYourLayoutBinding

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
         super.onCreateView(inflater, container, savedInstanceState)
        mDataBinding=DataBindingUtil.inflate(
            LayoutInflater.from(getContext()),
            R.layout.YOUR.LAYOUT.NAME,
            null,
            false
        )
        dialog?.let {
            it.window?.requestFeature(Window.FEATURE_NO_TITLE)
            it.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
        }
        return mDataBinding.root
    }



    override fun onStart() {
        super.onStart()
        dialog?:return
            val width = ViewGroup.LayoutParams.MATCH_PARENT
            val height = ViewGroup.LayoutParams.MATCH_PARENT
            dialog?.window?.setLayout(width, height)

    }

}
eagerprince
  • 115
  • 1
  • 5
0

This was a productive find to run a full screen dialog box:

AlertDialog.Builder(activity, R.style.Theme_AppName_PopupOverlay)

with the corresponding theme:

<!--night\theme-->
<style name="Theme.AppName.PopupOverlay" parent="ThemeOverlay.AppCompat.Light">
    <!--text-->
    <item name="colorPrimary">@color/white</item>
    <!--title-->
    <item name="android:textColor">@color/white</item>
    <!--window color-->
    <item name="android:backgroundTint">@color/grey_dark</item>
</style>

The Alert Dialog Builder also needs the reference to the PopupOverlay for the day theme. So I just have:

<style name="Theme.AppName.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
GotDots
  • 53
  • 1
  • 8