我无法从我的应用程序中删除操作栏

时间:2016-03-25 15:19:48

标签: android xml android-actionbar

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

Update for Microsoft Office 2010 (KB2965291) 32-Bit Edition Update for Microsoft Filter Pack 2.0 (KB2881026) 32-Bit Edition Update for Microsoft Visual Studio 2010 Tools for Office Runtime (KB3001652) Update for Microsoft Outlook 2010 (KB3015585) 32-Bit Edition Update for Microsoft Office 2010 (KB2956141) 32-Bit Edition Update for Microsoft Visio Viewer 2010 (KB2881021) 32-Bit Edition Update for Windows 7 for x64-based Systems (KB3006625)

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> v21:

styles.xml

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

我也在<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

但是只有在我运行应用程序时才删除它。我希望它在设计面板中消失。

这是怎么做到的?

3 个答案:

答案 0 :(得分:2)

  

但是只有在我运行应用程序时才删除它。我希望它是   进入了设计小组。

只需在Android Studio预览中使用不含ActionBar的主题:

enter image description here

我之所以这么说是因为你在编译应用程序后说它正在工作,你的问题是关于:

  

我希望它能够在设计面板

中消失

设计面板!

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

问题是,它应该是这样的:

Manifest

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

如果它仍然存在,您应该检查Toolbar

中是否有Layouts

答案 1 :(得分: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"

希望这会有所帮助!!

答案 2 :(得分:2)

转到此行manifest.xml

android:theme="@style/AppTheme"

删除Apptheme,而不是输入主题。带点(。)它会显示主题布局的不同选项。 按照图片:

pic1

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

snapshot

希望这会有所帮助;)