【问题标题】:Prevent Status Bar Appearance From Dialog Fragment防止对话框片段出现状态栏
【发布时间】:2015-08-11 23:19:14
【问题描述】:

我有一个非常标准的 Dialog 调用。问题是它会打开状态栏,当他们单击“确定”时我会隐藏它。您知道如何防止显示对话框时出现状态栏吗?

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

    // 2. Chain together various setter methods to set the dialog characteristics

    builder.setMessage("Please fill in the missing blocks in this layout with photos or choose a different layout.")
                                        .setTitle("Missing Photos");

                                // Add the buttons

builder.setPositiveButton("OK", new DialogInterface.OnClickListener()
  {
       public void onClick(DialogInterface dialog, int id)
      {
        hideSystemUI();
      }
  });

     // 3. Get the AlertDialog from create()
     AlertDialog dialog = builder.create();
     dialog.show();

【问题讨论】:

  • 当对话框显示时你能用 dialog.setOnShowListener(...) 调用 hideSystemUI() 吗?
  • 我试过了,状态栏还是出现了。

标签: java android android-alertdialog statusbar


【解决方案1】:

发生这种情况是因为您以编程方式隐藏了活动和片段的标题栏,而对话框仍然继承了您为应用设置的主题,并且该主题不会隐藏标题栏。您需要做的就是在styles.xml 中为您的对话框简单地指定一个自定义主题,然后在代码中将您的对话框主题设置为它。这是一个例子

<style name="CustomDialogTheme" parent="AppTheme"> 
    <item name="android:windowNoTitle">true</item>
</style>    

现在在您的代码中,像这样在对话框中设置自定义主题

dialog.setStyle( DialogFragment.STYLE_NORMAL, R.style.CustomDialogTheme);

【讨论】:

  • 您无法在对话框上设置样式,而必须在构建器上设置。设置主题也会使对话框占据整个屏幕。
猜你喜欢
  • 2014-10-06
  • 1970-01-01
  • 1970-01-01
  • 2014-02-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多