prevent状态栏外观从对话片段 [英] Prevent Status Bar Appearance From Dialog Fragment

查看:148
本文介绍了prevent状态栏外观从对话片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个pretty的标准对话框调用。问题是,它带来了状态栏和我隐藏它,当他们点击确定。你知道我可以prevent出现显示该对话框时,状态栏?

  AlertDialog.Builder建设者=新AlertDialog.Builder(getActivity());

    // 2。链在一起的各种setter方法​​来设置对话框特点

    builder.setMessage(请填写失踪块这样的布局与照片或选择不同的布局。)
                                        .setTitle(丢失的照片);

                                //添加按钮

builder.setPositiveButton(OK,新DialogInterface.OnClickListener()
  {
       公共无效的onClick(DialogInterface对话框,INT ID)
      {
        hideSystemUI();
      }
  });

     // 3.获取AlertDialog从创建()
     AlertDialog对话框= builder.create();
     dialog.show();
 

解决方案

这是因为你是隐藏标题栏以编程为你的活动和片段,而该对话框依然继承您已设置的应用程序的主题,这个主题没有按'躲藏的标题栏。所有你需要做的是简单的指定一个自定义主题在styles.xml你的对话框,然后设置你的对话主题,它在code。下面是一个例子

 <样式名称=CustomDialogTheme父=AppTheme>
    <项目名称=机器人:windowNoTitle>真< /项目>
< /风格>
 

现在在code设置custome主题,像这样的对话

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

I have a pretty standard Dialog call. The problem is it brings up the status bar and I hide it when they click OK. Do you know how I can prevent the status bar from appearing when the dialog is shown?

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

解决方案

It happens because you are hiding the title bar programmatically for your activities and fragments while the dialog still inherits the theme you have set for the app and that theme doesn't hide the title bar. All you need to do is to simple specify a custom theme for your dialog in styles.xml and then set your dialogs theme to it in code. Here is an example

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

Now in your code set the custome theme on the dialog like this

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

这篇关于prevent状态栏外观从对话片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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