【问题标题】:I can't remove the action bar from my application我无法从我的应用程序中删除操作栏
【发布时间】:2016-03-25 15:19:48
【问题描述】:

我正在尝试从我的应用程序中删除操作栏,但它就是不会离开。这是我所做的:

styles.xml

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>

    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

</resources>

styles.xmlv21:

<resources>>

    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        <item name="android:windowDrawsSystemBarBackgrounds">true</item>
        <item name="android:statusBarColor">@android:color/transparent</item>
    </style>
</resources>

应用主题设置为无操作栏。

我也在 MainActivity.java 课程中这样做:

getActionBar().hide();

但这只会在我运行应用程序时将其删除。我希望它在设计面板中消失。

这是怎么做到的?

【问题讨论】:

  • Android Studio 的设计面板?
  • 你的MainActivity.java在manifest文件中的主题是什么?你是否为你的活动设置了`android:theme`?
  • Theme.AppCompat.Light.NoActionBar 有“无操作栏”...但AppTheme.NoActionBar 没有扩展该主题...
  • 您是否尝试过清单中的android:theme="@android:style/Theme.NoTitleBar"&gt;
  • 你也可以添加你的清单吗?

标签: android xml android-actionbar


【解决方案1】:

但这只会在我运行应用程序时将其删除。我希望它是 在设计面板中消失了。

简单地说,在 Android Studio 的预览版上使用不带 ActionBar 的主题:

我这么说是因为您说它在编译应用程序后可以工作,而您的问题是:

我希望它在设计面板

中消失

设计面板!


但是,这只会向您展示如何在 Andorid Studio 的预览版中删除 ActionBar

问题是,应该是这样的:

Manifest:

<android:theme="@android:style/Theme.NoTitleBar">

如果它仍然存在,您应该检查您的Layouts 中是否有Toolbar

【讨论】:

    【解决方案2】:

    你错过了parent属性:

    <style name="AppTheme.NoActionBar" parent="AppTheme">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>
    

    同样:

    <style name="AppTheme.NoActionBar" parent="AppTheme">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        <item name="android:windowDrawsSystemBarBackgrounds">true</item>
        <item name="android:statusBarColor">@android:color/transparent</item>
    </style>
    

    别忘了在manifest 中添加主题声明:

    android:theme="@style/AppTheme.NoActionBar"
    

    希望这会有所帮助!

    【讨论】:

      【解决方案3】:

      在此行转到您的manifest.xml

      android:theme="@style/AppTheme"
      

      删除Apptheme,而不是输入主题。带有一个点 (.),它将向您显示不同的主题布局选项。 跟着图片走:

      这只会影响模拟器。为了也看到activity_main.xml中的效果,只需继续该选项卡活动并按下,形成预览窗口,右上角没有按钮“NoActionBar”,如下图所示,从对话框中选择“清单主题”并点击确定。 这也会改变预览!

      希望这会有所帮助;)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-08-08
        • 2015-01-16
        • 1970-01-01
        • 1970-01-01
        • 2016-09-27
        相关资源
        最近更新 更多