Android 隐藏ActionBar在顶部留下空白
我想把ActionBar隐藏在我的一个片段中,但是当我调用Android 隐藏ActionBar在顶部留下空白,android,Android,我想把ActionBar隐藏在我的一个片段中,但是当我调用 ((MainActivity)getActivity()).getActionBar().hide() 在碎片上我得到了这样的东西 如何删除空白并使其成为“全屏”——我希望显示通知栏 [编辑:] 最小SDK不是4.0,但当我启动此应用程序时,我将其设置为2.3,我必须使用appcompant 主活动xml <android.support.v4.widget.DrawerLayout xmlns:android="htt
((MainActivity)getActivity()).getActionBar().hide()代码>
在碎片上我得到了这样的东西
如何删除空白并使其成为“全屏”——我希望显示通知栏
[编辑:]
最小SDK不是4.0,但当我启动此应用程序时,我将其设置为2.3,我必须使用appcompant
主活动xml
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg"
tools:context="com.mariusz.myapp.MainActivity" >
<!--
As the main content view, the view below consumes the entire
space available using match_parent in both dimensions.
-->
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="?android:attr/actionBarSize" />
<!--
android:layout_gravity="start" tells DrawerLayout to treat
this as a sliding drawer on the left side for left-to-right
languages and on the right side for right-to-left languages.
If you're not building against API 17 or higher, use
android:layout_gravity="left" instead.
-->
<!--
The drawer is given a fixed width in dp and extends the full height of
the container.
-->
<fragment
android:id="@+id/navigation_drawer"
android:name="com.mariusz.myapp.NavigationDrawerFragment"
android:layout_width="@dimen/navigation_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"
android:paddingTop="?android:attr/actionBarSize" />
</android.support.v4.widget.DrawerLayout>
库片段xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<android.support.v4.view.ViewPager
android:id="@+id/gallery_pager"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</android.support.v4.view.ViewPager>
</LinearLayout>
[编辑解决方案]
最好的解决方案是创建其他活动来显示没有actionbar的图像,仅在清单文件中的该活动中使用这一行android:theme=“@android:style/theme.Black.NoTitleBar”
添加getActionBar().hide()代码>在活动类中,您的片段在其中调用并使用getActionBar().show()中的一些其他片段代码>您应该对活动进行结构化,使其覆盖在操作栏上:下面是一个您可能使用的主题示例:
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
parent="@android:style/Theme.Holo">
<item name="android:windowActionBarOverlay">true</item>
</style>
</resources>
真的
更多信息。此外,如果您不打算总是隐藏Actionbar,那么您可能需要构建布局,以便在Actionbar可见时对其进行说明。请参阅如何做到这一点。你也可以考虑将你的片段重构为一个单独的活动,然后立即使用全屏模式启动它,通过使用该活动的“NoTITLE BARTHOST”。
requestWindowFeature(Window.FEATURE_NO_TITLE);
我也遇到了同样的问题,我的问题是在xml中包含fitsSystemWindows
标记,这将使整个活动没有Actionbar,这将影响其他片段,他似乎希望能够通过编程方式显示/隐藏Actionbar。同意我只需要在一个片段中进行操作我检查了这些东西。我得到了答案,尝试一下,让我通知你。在我发布它之前我已经做过了true@null@style/NButton@style/neditext@style/NActionBar
你的最小SDK是什么?另外,您还有一个额外的“windowActionBarOverlay”项目,前面缺少“android:”字样。我认为您的活动和片段XML会有所帮助,请发布它们。这只能在将内容添加到窗口之前使用-一旦活动启动并运行,当你添加/删除一个片段时,它会抛出一个AndroidRuntimeException。只是提醒你接受一个对你帮助最大的答案作为正确答案。