Android使Dialog全屏显示状态栏

Cal*_*ung 7 android dialog

我想创建一个全屏但没有隐藏状态栏的对话框.

如果使用样式Theme_Light_NoTitleBar_Fullscreen,则对话框占据整个屏幕.

如果使用样式Theme_Material_Light_NoActionBar_TranslucentDecor,它似乎工作,但对话框的顶部实际上变得透明.我可以通过查询状态栏高度并在我的对话框布局中添加顶部填充来使其更好.这个解决方案似乎工作正常,但如果我将动画附加到它上面它不起作用.

我很困惑为什么谷歌使对话框如此复杂使用,如果我正确地做了一个全屏对话框在这里?

Sat*_*eri 10

只需使用THEME_BLACK_NoTitleBar 为我工作!!!


ucM*_*dia 6

也许为时已晚,但为了其他有同样问题的人:

    dialog = new dialog(context,android.R.style.Theme_Translucent_NoTitleBar);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);

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


小智 2

我从博客中找到了一个片段,经过几次尝试,我发现我必须Theme_Black_NoTitleBar_Fullscreen在构造函数中与onCreate. 现在我的对话框是全屏的并显示状态栏。

public YourCustomDiag(Activity act){
    //step 1, required. to stretch the dialog to full screen
    super(act, android.R.style.Theme_Black_NoTitleBar_Fullscreen);
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.custom_dialog_layout);
    KeepStatusBar();
}

//step 2, required
private void KeepStatusBar(){    
    WindowManager.LayoutParams attrs = getWindow().getAttributes();
    attrs.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN;
    getWindow().setAttributes(attrs);
}
Run Code Online (Sandbox Code Playgroud)

这是我找到代码片段的来源