使用AlertDialog.Builder时防止显示StatusBar [英] Prevent StatusBar from showing when using AlertDialog.Builder

查看:189
本文介绍了使用AlertDialog.Builder时防止显示StatusBar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MainActivityXML中,我对其进行了编程,以使它使用带有NoActionBar的主题,因此没有显示操作栏.但是,每当我要显示对话框时,我都会调用使用AlertDialog.Builder来创建对话框的DialogFragments之一.当我从主要活动中显示对话框时,它将显示带有ActionBar的对话框. 然后我关闭对话框时,动作栏仍然存在.

In the XML of my MainActivity, I have programmed it so that it uses a theme with NoActionBar and therefore there is no action bar displayed. However, whenever I want to display a dialog, I call one of my DialogFragments that uses an AlertDialog.Builder to create the dialog. When I show the dialog from within the main activity, it shows the dialog with the ActionBar. When I then close the dialog box, the action bar remains.

问题:当片段消失或它最初没有显示时,我如何保持一致性并隐藏操作栏?

QUESTION: How do I have consistency and hide the action bar when the fragment disappears, or have it not display in the first place?

我尝试创建自定义样式,然后将其包装在ContextThemeWrapper中无济于事.

I have tried creating a custom style and then wrapping that in a ContextThemeWrapper to no avail.

getActionBar().hide()getSupportActionBar().hide()在主要活动和片段上均返回null.

getActionBar().hide() and getSupportActionBar().hide() returns null both on the main activity and the fragment.

myDialog.getDialog()(在调用.show()之前)返回null.

myDialog.getDialog() in the MainActivity (before .show() is called) returns null.

我用来创建AlertDialog.Builder的代码在DialogFragmentonCreateDialog之内:

The code I have used to create the AlertDialog.Builder is within DialogFragment's onCreateDialog:

AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
     builder.setTitle(R.string.delete_confirmation)
            .setItems(fileSequence, new DialogInterface.OnClickListener()
            {
                public void onClick(DialogInterface dialog, int which)
                {
                    File loadedFile = fileFullArray.get(which);

                    boolean deleted = loadedFile.delete();

                    if (deleted)
                        Toast.makeText(getActivity().getApplicationContext(), "File deleted!", Toast.LENGTH_SHORT).show();
                }
            })
            .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener()
                    {
                        public void onClick(DialogInterface dialog, int id)
                        {
                            // User cancelled the dialog
                        }
                    }
            );
    // Create the AlertDialog object and return it
    return builder.create();

回到这四个月后,此修复程序在对话框的onCreate()中添加了以下行:

Came back to this 4 months later and the fix was adding the following line in the Dialog's onCreate():

this.getActivity().getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

片段的onCreate()被覆盖,被写在MainActivity中.干杯.

The Fragment's onCreate() was overwriting was written in the MainActivity. Cheers.

推荐答案

以下行需要添加到对话框的onCreate()

The following line needed to be added to my Dialog's onCreate()

this.getActivity().getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

这篇关于使用AlertDialog.Builder时防止显示StatusBar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆