【问题标题】:Android make Dialog fullscreen with status bar showingAndroid使对话框全屏显示状态栏
【发布时间】:2016-05-20 04:42:42
【问题描述】:

我想制作一个全屏但不隐藏状态栏的对话框。

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

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

我很困惑为什么谷歌让对话框使用起来如此复杂,如果我做得正确,在这里制作一个全屏对话框?

【问题讨论】:

    标签: android dialog


    【解决方案1】:

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

    【讨论】:

    • 为我工作。最佳解决方案!
    • 也为我工作,这个答案应该得到更多的支持。
    • 我找不到这个主题,至少在 androidx 上
    • 我想将状态栏设置为白色,并使用这个或浅色主题.. 它一直显示黑色状态栏
    【解决方案2】:

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

        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);
    

    【讨论】:

      【解决方案3】:

      使用 android.R.style.Theme_Black_NoTitleBar

      AlertDialog.Builder builder = new AlertDialog.Builder(context,
                         android.R.style.Theme_Black_NoTitleBar);
      

      Example screen

      【讨论】:

        【解决方案4】:

        我从博客中找到了一个snipplet,经过几次尝试后我发现我必须在构造函数中使用Theme_Black_NoTitleBar_Fullscreen,以及onCreate 期间的snipplet。现在我的对话框全屏显示状态栏。

        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);
        }
        

        this is the source where i found the snipplet

        【讨论】:

          【解决方案5】:

          你可以使用

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

          这将为状态栏使用primaryDarkColor。

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2013-08-21
            • 2021-10-07
            • 1970-01-01
            • 2012-05-11
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2017-09-16
            相关资源
            最近更新 更多