160

I have a GridView and i want to make an implémentation of a dialog, on which the picture that i have selected should display in full screen.

so how can i make the dialog shows in a full screen mode ? thanks!

Ayoub_Prog
  • 196
  • 2
  • 11
user790156
  • 2,718
  • 5
  • 20
  • 20
  • 2
    If you want to use a FULL SCREEN `Dialog`, why not just use the default `ACTION_VIEW` `Intent` for image files? – Will Tate Jun 13 '11 at 10:45
  • sorry I mean almost full screen or full image – user790156 Jun 13 '11 at 10:49
  • 3
    In conjunction with answer to willytate if you have to dialog then use android.R.style.Theme_Translucent_NoTitleBar_Fullscreen in theme – ingsaurabh Jun 13 '11 at 10:50
  • This might help http://stackoverflow.com/a/2700683/1118886 – Sheraz Ahmad Khilji Jul 26 '12 at 07:06
  • I do NOT understand why this question get closed. Annoying. Have a suggestion, but can't post. Kudos to @Andrew Barber!!! -.- – Martin Pfeffer Apr 18 '17 at 11:58
  • 3
    @MartinPfeffer i also have a suggestion for future user but question closed Andrew Barber is not from android community. this is really a simple question new android developers always curious about this. this question should be open again for better answers and future users – Abhishek Singh Mar 23 '18 at 07:42

5 Answers5

268

try

Dialog dialog=new Dialog(this,android.R.style.Theme_Black_NoTitleBar_Fullscreen)
Gk Mohammad Emon
  • 6,084
  • 3
  • 42
  • 42
Ahmed Salem
  • 3,947
  • 1
  • 21
  • 40
109

based on this link , the correct answer (which i've tested myself) is:

put this code in the constructor or the onCreate() method of the dialog:

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

in addition , set the style of the dialog to :

<style name="full_screen_dialog">
    <item name="android:windowFrame">@null</item>
    <item name="android:windowIsFloating">true</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
    <item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
</style>

this could be achieved via the constructor , for example :

public FullScreenDialog(Context context)
{
  super(context, R.style.full_screen_dialog);
  ...

EDIT: an alternative to all of the above would be to set the style to android.R.style.ThemeOverlay and that's it.

EDIT2: To support material library, add Gradle dependency to app(module) build.gradle file

implementation "com.google.android.material:material:$material_version"

Then set dialog's theme to R.style.ThemeOverlay_MaterialComponents

Yeung
  • 2,202
  • 2
  • 27
  • 50
android developer
  • 114,585
  • 152
  • 739
  • 1,270
  • With my try, this one is the only work one. `android.R.style.ThemeOverlay` is the key. – Yeung Jun 11 '21 at 11:31
  • @Yeung I wonder if `ThemeOverlay.MaterialComponents` is also suitable. Can you please check? – android developer Jun 12 '21 at 00:31
  • 1
    Tried. It works, but don't know it is useful or not as I am developing with an old Android 5 device. – Yeung Jun 15 '21 at 08:13
  • @Yeung I think it's better than what I wrote, then. Supports new material library. Can you please write me what exactly you did, so that I could update my answer ? Or maybe you could edit mine? – android developer Jun 15 '21 at 10:41
  • When deal with old issue, just found this also has reference value `getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(any bg color));` will "expand" the dialog's width to fullscreen which no need to set theme `android.R.style.ThemeOverlay` . Notice that for "width" only. – Yeung Jun 22 '21 at 06:31
  • For me `ThemeOverlay.MaterialComponents` was enough. Thanks. – Ahmad Reza Enshaee Oct 13 '22 at 14:28
67

The easiest way I found

Dialog dialog=new Dialog(this,android.R.style.Theme_Black_NoTitleBar_Fullscreen);
        dialog.setContentView(R.layout.frame_help);
        dialog.show();
Javier Roberto
  • 1,293
  • 11
  • 17
46

EDIT Until such time as StackOverflow allows us to version our answers, this is an answer that works for Android 3 and below. Please don't downvote it because it's not working for you now, because it definitely works with older Android versions.


You should only need to add one line to your onCreateDialog() method:

@Override
protected Dialog onCreateDialog(int id) {
    //all other dialog stuff (which dialog to display)

    //this line is what you need:
    dialog.getWindow().setFlags(LayoutParams.FLAG_FULLSCREEN, LayoutParams.FLAG_FULLSCREEN);

    return dialog;
}
Caspar Harmer
  • 8,097
  • 2
  • 42
  • 39
43
dialog = new Dialog(getActivity(),android.R.style.Theme_Translucent_NoTitleBar);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.loading_screen);
    Window window = dialog.getWindow();
    WindowManager.LayoutParams wlp = window.getAttributes();

    wlp.gravity = Gravity.CENTER;
    wlp.flags &= ~WindowManager.LayoutParams.FLAG_BLUR_BEHIND;
    window.setAttributes(wlp);
    dialog.getWindow().setLayout(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    dialog.show();

try this.

Prateek Sharma
  • 651
  • 9
  • 18