How to set dialog to show in full screen? [closed]
Asked Answered
S

5

162

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!

Simone answered 13/6, 2011 at 10:41 Comment(6)
If you want to use a FULL SCREEN Dialog, why not just use the default ACTION_VIEW Intent for image files?Diagnostician
sorry I mean almost full screen or full imageSimone
In conjunction with answer to willytate if you have to dialog then use android.R.style.Theme_Translucent_NoTitleBar_Fullscreen in themeRamify
This might help https://mcmap.net/q/53180/-how-do-i-create-a-transparent-activity-on-androidTrusting
I do NOT understand why this question get closed. Annoying. Have a suggestion, but can't post. Kudos to @Andrew Barber!!! -.-Feasible
@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 usersAlwitt
H
270

try

Dialog dialog=new Dialog(this,android.R.style.Theme_Black_NoTitleBar_Fullscreen)
Hartsfield answered 29/9, 2011 at 12:16 Comment(12)
For this to work for me I had to use android.R.style.Theme_Black_NoTitleBar_FullscreenHorrocks
Call requires API level 11Tysontyumen
@LuisA.Florit try Theme_Black_NoTitleBar_FullscreenCookshop
What about fullscreen with a titlebar?Reversion
When I do this (using DialogFragment) I see the status bar color is killed by the dialog, the whole screen is the dialog's background color. Does anyone know of a workaround? I tried setting the statusBarColor of the dialog's window, to no effect. P.S.: navigation bar color gets killed too.Promoter
But it gets black color as background how to change it?Disproportionation
still shows a gap where the statusbar should be...Yaws
you could use any theme with Fullscreen at the end of it, for me android.R.style.Theme_Holo_NoActionBar_Fullscreen worked the best, Theme_Black adds backgrounds to my EditTexts.Derrik
@Ahmed Salem Tnx You saved my time. +1 vote for uPulpit
In kotlin it is: dialog = Dialog(context!!, android.R.style.Theme_Black_NoTitleBar_Fullscreen)Decode
know its changed to myAppAdsDialog=new Dialog(this,android.R.style.Theme_Black_NoTitleBar_Fullscreen);Helotism
For fullscreen Dialog with titlebar you can use android.R.style.Theme_Black_NoTitleBarLanguishment
D
110

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

Discourtesy answered 3/6, 2012 at 9:49 Comment(6)
With my try, this one is the only work one. android.R.style.ThemeOverlay is the key.Nate
@Nate I wonder if ThemeOverlay.MaterialComponents is also suitable. Can you please check?Discourtesy
Tried. It works, but don't know it is useful or not as I am developing with an old Android 5 device.Nate
@Nate 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?Discourtesy
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.Nate
For me ThemeOverlay.MaterialComponents was enough. Thanks.Ribbonwood
O
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();
Opinicus answered 16/4, 2014 at 14:35 Comment(1)
cant change background color, still blackAcrilan
D
47

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;
}
Downy answered 13/6, 2011 at 10:50 Comment(10)
Why I can't use FLAG_FULLSCREENSimone
Well, that's hard to say - Did you import LayoutParams? Is your layout xml set to either fill_parent or match_parent?Downy
use android.view.WindowManager.LayoutParams.FLAG_FULLSCREENRolypoly
ERROR: FLAG_FULLSCREEN cannot be resolved or is not a fieldTysontyumen
It's possible that this answer is getting out of date - it might not work for android 4.0 and up.Downy
@CaspNZ In android 4.0+, you should override the DialogFragments onCreateDialog method. This way, everything is cool. ;-)Avaavadavat
This was driving me nuts, whenever I created the Dialog the top region was clipped although it seems the window was actually fully sized (e.g. the window background was also clipped). I set LayoutParams.FLAG_FULLSCREEN after requestWindowFeature(Window.FEATURE_NO_TITLE) but before setContentView()Ardine
you need to import like: import android.view.WindowManager;Mugger
this not worked for me .... in api 18 ... android studio emulatorUnreserve
This is a very old answer. It's possible that it no longer works in newer versions of the APIDowny
N
45
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.

Nacred answered 7/4, 2014 at 12:31 Comment(1)
MATCH_PARENT worked for me.Symbolism

© 2022 - 2024 — McMap. All rights reserved.