【问题标题】:Android remove title bar from Action barAndroid从操作栏中删除标题栏
【发布时间】:2014-09-25 12:03:52
【问题描述】:

我的应用中有一个活动,它使用带有操作栏的可滑动标签

例如:-

this tutorial

所以我的问题是在我的活动中添加操作栏并删除标题栏

similar question

【问题讨论】:

标签: android android-fragments android-actionbar android-titlebar


【解决方案1】:

我不确定您将什么归类为标题栏,但您可以在 XML 中执行此操作,方法是在您的 Android 清单中为特定活动添加以下内容以删除您的标题栏。

android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen

【讨论】:

  • 我认为这不会起作用,因为在清单文件中设置主题不会影响片段
【解决方案2】:

在调用 setContentView() 之前将此添加到您的活动中;

this.requestWindowFeature(Window.FEATURE_ACTION_BAR | Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
             WindowManager.LayoutParams.FLAG_FULLSCREEN);

如果这不起作用,试试这个

//use this to disable the icon from ActionBar
    getActionBar().setDisplayShowHomeEnabled(false);

    //use this to disable the application name from ActionBar
    getActionBar().setDisplayShowTitleEnabled(false);

【讨论】:

    【解决方案3】:

    在添加内容之前,在活动的 oncreate() 方法中使用此代码:

     getWindow().requestFeature(Window.FEATURE_NO_TITLE)
    

    【讨论】: