如何设置对话框以全屏显示?

use*_*156 118 android android-fullscreen

我有一个显示大量图像的GridView,当我点击任何图像时,它将在全屏对话框中 显示完整图像

请告诉我该怎么做

谢谢.

Ahm*_*lem 218

尝试

Dialog dialog=new Dialog(this,android.R.style.Theme.Black.NoTitleBar.Fullscreen)
Run Code Online (Sandbox Code Playgroud)

  • 为了这个为我工作,我不得不使用android.R.style.Theme_Black_NoTitleBar_Fullscreen (27认同)
  • 全屏_with_标题栏怎么样? (20认同)
  • `调用需要API级别11` (4认同)
  • 当我这样做时(使用“DialogFragment”),我看到状态栏颜色被对话框杀死,整个屏幕都是对话框的背景颜色。有谁知道解决方法?我尝试设置对话框窗口的 statusBarColor,但没有效果。PS:导航栏颜色也会被杀死。 (2认同)

and*_*per 77

根据这个链接,正确的答案(我自己测试过)是:

将此代码放在构造函数或onCreate()对话框的方法中:

getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT,
                WindowManager.LayoutParams.MATCH_PARENT);
Run Code Online (Sandbox Code Playgroud)

另外,将对话框的样式设置为:

<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>
Run Code Online (Sandbox Code Playgroud)

这可以通过构造函数来实现,例如:

public FullScreenDialog(Context context)
{
  super(context, R.style.full_screen_dialog);
  ...
Run Code Online (Sandbox Code Playgroud)

编辑:以上所有的替代方案是将样式设置为android.R.style.Theme就是这样.


Jav*_*rto 48

我找到的最简单的方法

Dialog dialog=new Dialog(this,android.R.style.Theme_Black_NoTitleBar_Fullscreen);
        dialog.setContentView(R.layout.frame_help);
        dialog.show();
Run Code Online (Sandbox Code Playgroud)


Cas*_*mer 38

编辑直到StackOverflow允许我们对答案进行编辑,这是一个适用于Android 3及更低版本的答案.请不要贬低它,因为它现在不适合你,因为它绝对适用于较旧的Android版本.


您只需要在方法中添加一行onCreateDialog():

@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;
}
Run Code Online (Sandbox Code Playgroud)

  • 使用android.view.WindowManager.LayoutParams.FLAG_FULLSCREEN (11认同)
  • 嗯,这很难说 - 你导入了LayoutParams吗?您的布局xml是设置为fill_parent还是match_parent? (2认同)
  • 这个答案可能已经过时了 - 它可能不适用于 android 4.0 及更高版本。 (2认同)

Pra*_*rma 33

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();
Run Code Online (Sandbox Code Playgroud)

试试这个.

  • MATCH_PARENT 为我工作。 (2认同)