【问题标题】:How can I remove the action bar from a dialog如何从对话框中删除操作栏
【发布时间】:2016-05-23 18:33:27
【问题描述】:

getActionBar().hide();将崩溃导致 getActionBar 为空。 这也不起作用:

<style name="NoActionBar" parent="@android:style/Theme.Holo.Light">
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
</style> 

这是我的代码:

  public static void popupWindow(final Context context,String title ,String desc,final CrudStateCallback back){
    final Dialog dialog = new Dialog(context, R.style.ShowPopup);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.R.color.transparent));
    dialog.setContentView(R.layout.sticky_layout);
    colourTitleBar(context, dialog);
    String sansproEL = "fonts/source_sans_pro_extraLight.ttf";
    String sansproL = "fonts/source_sans_pro_light.ttf";
    Typeface sansproL_TF = Typeface.createFromAsset(context.getAssets(), sansproL);
    Typeface sansproEL_TF = Typeface.createFromAsset(context.getAssets(), sansproEL);
    ((TextView)dialog.findViewById(R.id.popup_text)).setTypeface(sansproL_TF);
    ((TextView)dialog.findViewById(R.id.popup_text2)).setTypeface(sansproEL_TF);
    TextView text = (TextView) dialog.findViewById(R.id.popup_text);
    TextView text2 = (TextView) dialog.findViewById(R.id.popup_text2);
    RelativeLayout container = (RelativeLayout) dialog.findViewById(R.id.all_container);
    View.OnClickListener dismissList = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dialog.dismiss();
            if(back!= null)
                back.onResponse("");
        }
    };
    text.setText(title);
    text2.setText(desc);
    container.setOnClickListener(dismissList);
    PSLocationCenter.getInstance().instabug.setDialog(dialog);
    dialog.show();
    Handler han = new Handler();
    han.postDelayed(new Runnable() {
        @Override
        public void run() {
            try{
                dialog.dismiss();
            }catch (Exception e){
                Log.i("","error in popup window");
            }
            if(back!= null)
                back.onResponse("");
        }
    }, 3000);
}

  public static void colourTitleBar(Context context, Dialog dialog) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        dialog.getWindow().setStatusBarColor(context.getResources().getColor(android.R.color.transparent));
    }
}

还有我的风格:

<style name="ShowPopup">
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowAnimationStyle">@style/ShowPopupAnimation</item>
    <item name="android:windowCloseOnTouchOutside">true</item>
    <item name="android:windowActionBar">false</item>
    <item name="android:windowTitleSize">0dp</item>

【问题讨论】:

    标签: android dialog android-actionbar styles


    【解决方案1】:

    使用 Theme.Holo.Light.NoActionBar 作为您的主题的父级怎么样?

    【讨论】:

    • 我会在我周一上班的时候给我答复
    • 使用 *.NoActionBar 主题无需以编程方式删除 ActionBar。根据您的项目上下文,这可能是也可能不是一个好的解决方案。不客气!
    【解决方案2】:

    您是否尝试简单地删除此行?

    colourTitleBar(context, dialog);
    

    【讨论】:

    • 我刚刚添加了那个。这将使状态栏消失。这就是我添加它的原因。还有条形图,无论是状态还是动作,我们都是不可见的。在更新到最新的 SDK 和 Android Studio 版本之前。
    【解决方案3】:

    您是要删除 ActionBar 还是 Dialog 的标题栏?如果是第一个,您可以尝试在 Activity 上调用 requestWindowFeature(),而不是在 Dialog 上。如前所述,在 setContentView() 之前。

    【讨论】:

    • 我需要从对话框中删除 actionBar,所以它会保留在活动中
    • 你不能用 getActivity().getActionbar().hide() 或 getSupportActionBar().hide() 隐藏它...,然后在关闭对话框时用 show 把它拿回来()?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-24
    • 2012-10-28
    • 2015-03-16
    • 1970-01-01
    相关资源
    最近更新 更多