隐藏 ActionBar 顶部留有空白

Mar*_*usz 5 android

我想将 ActionBar 隐藏在我的一个片段中,但是当我打电话时

((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>
Run Code Online (Sandbox Code Playgroud)

图库片段 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>
Run Code Online (Sandbox Code Playgroud)

[编辑解决方案]

最佳解决方案是创建其他活动来显示没有操作栏的图像

pra*_*ash 0

android:theme="@android:style/Theme.Black.NoTitleBar"仅在清单文件中的该活动中使用此行

在您的片段调用的活动类中添加getActionBar().hide(); 并使用 中的一些其他片段getActionBar().show();