47

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 <item name="android:windowFullscreen">true</item> but nothing seems to be working.

I found a way of getting rid of the Title bar, but couldn't find a way to put a dialog in full screen. So can any one suggest me a way to do it.

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyTheme" parent="@android:style/Theme.Dialog">
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowFrame">@null</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowIsFloating">true</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowBackground">@color/dialog_background</item>
</style>
</resources>
Bob
  • 881
  • 2
  • 10
  • 16

14 Answers14

107

Give its constructor a non-dialog theme, such as android.R.style.Theme or android.R.style.Theme_Light.

Code by @Bob.

Dialog dialog = new Dialog(context, android.R.style.Theme_Light); 
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 
dialog.setContentView(R.layout.MyCustomDialogLayout); 
dialog.show();
dd619
  • 5,910
  • 8
  • 35
  • 60
Renard
  • 6,909
  • 2
  • 27
  • 23
  • This one works pretty cool. the Dialog is coming in full screen with out any borders. thanks... – Bob Apr 16 '12 at 12:04
  • 1
    Its great! For NoTitle fullscreen dialog I used "@android:style/Theme.Black.NoTitleBar" as my dialog's theme parent. – Alex Mar 27 '13 at 07:48
  • 1
    This works great for that purpose (full screen dialog), however the cancelable property is not working anymore. Any ideas? – IsaacCisneros Jun 21 '13 at 03:20
  • android.R.style.Theme_DeviceDefault_Dialog_MinWidth use this for minimum width of device. – Zala Janaksinh Jan 06 '16 at 09:59
35

Following code works in my case :

dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 
dialog.setContentView(R.layout.mydialog2);
dialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
Kaushik
  • 6,150
  • 5
  • 39
  • 54
Nibha Jain
  • 7,742
  • 11
  • 47
  • 71
  • I tried this one but it is not working in my code, I couldn't find the reason why. But the [Renard](http://stackoverflow.com/a/10173576/970272) code is working perfectly. – Bob Apr 16 '12 at 12:08
  • 1
    dialog.getWindow().setLayout(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); worked for me – user1767260 Aug 13 '13 at 11:55
20

Try this

dialog = new Dialog(context,android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
Kaushik
  • 6,150
  • 5
  • 39
  • 54
Lakshmanan
  • 1,671
  • 2
  • 26
  • 42
5

1.custom your dialog style

 <style name = "MyDialog" >
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowFullscreen">true</item>
        <item name="android:windowIsTranslucent">true</item>
        <item name = "android:windowContentOverlay" >@null</item >
        <item name = "android:colorBackgroundCacheHint" >@null</item >
        <item name = "android:backgroundDimEnabled">true</item>
        <item name = "android:windowBackground" >@android:color/transparent</item >
    </style >

2 :custom your dialog

WindowManager wm = (WindowManager) this.getSystemService(Context.WINDOW_SERVICE);
            int width = wm.getDefaultDisplay().getWidth();
            int height = wm.getDefaultDisplay().getHeight();
            final Dialog dialog = new Dialog(this, R.style.MyDialog);
            View view = LayoutInflater.from(this).inflate(R.layout.layout_dialog, null);

            WindowManager.LayoutParams params = dialog.getWindow().getAttributes();
            params.width = WindowManager.LayoutParams.MATCH_PARENT;
            params.height = WindowManager.LayoutParams.WRAP_CONTENT;

            dialog.setContentView(view);
            dialog.getWindow().setGravity(Gravity.BOTTOM);
            dialog.getWindow().setWindowAnimations(R.style.mydialog_Style);
            dialog.show();
Allen
  • 199
  • 2
  • 8
  • This is the best answer so far for me. I tried @Renard answer, that also worked but was making the whole background of the custom dialog black. I used to set the background color to themes, but instead of changing the color according to the themes, it goes completely black. – AR Sharif Uddin JUMMAN Aug 17 '23 at 12:01
3

The answer does not work for me(sdk 21, samsung galaxy s5). After searching and testing, I find that the key point for setting a dialog for fullscreen is the <item name="android:windowIsFloating">false</item> in your dialog style. Most styles of Dialog in sdk set it true! Set it false in a style and use it in

AlertDialog.Builder = new AlertDialog.Builder(getActivity(), R.style.YourStyle);

your style may look like

<style name="YourStyle">
    <item name="android:windowIsFloating">false</item>
    ...
</style>

after setting it false, it should be fullscreen. And more, you can use

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

to set it's height to wrap_content. Hope to help someone.

AssIstne
  • 466
  • 4
  • 13
3

Try wrapping your dialog_custom_layout.xml into RelativeLayout . That worked for me.

Milad Faridnia
  • 9,113
  • 13
  • 65
  • 78
Ayan
  • 8,192
  • 4
  • 46
  • 51
3

For full screen dialog you should extend DialogFragment it will provide Fragment life cycle methods and this is the recommended way in Android developer documents you can use simple Dialog or AlertDialog also.

When you create dialog instance just use android.R.style.Theme_Black_NoTitleBar_Fullscreen theme with context like this :

Dialog dialog = new Dialog(getActivity(), android.R.style.Theme_Black_NoTitleBar_Fullscreen);

or

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

This will show the dialog in full screen.

CopsOnRoad
  • 237,138
  • 77
  • 654
  • 440
Biswajit
  • 1,829
  • 1
  • 18
  • 33
1

try this code

protected void openDialog() {
        Dialog dialog = new Dialog(this);
        dialog.addContentView(new View(this), (new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT)));
        dialog.show();
    }
vipin
  • 2,851
  • 4
  • 18
  • 32
1

I'm using a Activity with Dialog theme. In this case, fullscreen worked this way:

int mUIFlag = View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
            | View.SYSTEM_UI_FLAG_FULLSCREEN
            | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;

@Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().getDecorView().setSystemUiVisibility(mUIFlag);

        getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
        setContentView(R.layout.lockscreen_activity);
}
Hamburg is nice
  • 369
  • 4
  • 10
1

Create your Custom Dialog as

Dialog dialog = new Dialog(context, android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
CopsOnRoad
  • 237,138
  • 77
  • 654
  • 440
venu46
  • 419
  • 5
  • 10
1

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

<?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:background="@color/colorPrimary">

    <!-- Your dialog content here -->

</LinearLayout>

Step 2: Define a new style in styles.xml named FullScreenDialog

<style name="FullScreenDialog" parent="Theme.AppCompat.Dialog">
    <item name="android:windowBackground">@android:color/transparent</item>
</style>

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();
    }
}
Son Truong
  • 13,661
  • 5
  • 32
  • 58
0

Full Screen dialog with Databinding

    fun showUserQrCode(
    mContext: Activity,
    showAddMore: Boolean,
    message: String?,
    skipClick: View.OnClickListener?,
    addMoreClick: View.OnClickListener?
) {

    val dialog = Dialog(mContext, android.R.style.Theme_Black_NoTitleBar_Fullscreen)
    val discountBinding: PopupUserQrCodeBinding = DataBindingUtil.inflate(
        LayoutInflater.from(mContext),
        R.layout.popup_user_qr_code,
        null,
        false
    )
    discountBinding.btnSkip.setOnClickListener(skipClick)


    dialog.setContentView(discountBinding.root)
    dialog.show()
}

Without Binding

    val dialog = Dialog(mContext, android.R.style.Theme_Black_NoTitleBar_Fullscreen)
    dialog.setContentView(R.layout.slider_layout)
    dialog.show()
Sandeep Pareek
  • 1,636
  • 19
  • 21
0

Try something like:

Dialog dialog = new Dialog(this, android.R.style.Theme_Black_NoTitleBar_Fullscreen);
dialog.setContentView(R.layout.my_content);
dialog.show();

Basically uses a non-dialog theme for dialog.
Path in styles.xml would be: @android:style/Theme.Translucent.NoTitleBar.Fullscreen

Top-Master
  • 7,611
  • 5
  • 39
  • 71
0

In Kotlin

val dialog = Dialog(this, android.R.style.Theme_Light)
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE)
        dialog.setContentView(R.layout.level_complete)
        dialog.show()
        dialog.setCancelable(false)
Jake
  • 31
  • 4