Android 安卓操作栏是不可见的,但仍在使用

Android 安卓操作栏是不可见的,但仍在使用,android,android-actionbar,Android,Android Actionbar,我试图隐藏android操作栏,我在清单中尝试了以下操作: android:theme="@android:style/Theme.NoTitleBar" 并在我的活动的onCreate方法中尝试了以下操作: super.onCreate(savedInstanceState); getWindow().requestFeature(Window.FEATURE_ACTION_BAR); getActionBar().hide(); setContentView(R.layout.view

我试图隐藏android操作栏,我在清单中尝试了以下操作:

android:theme="@android:style/Theme.NoTitleBar"
并在我的活动的onCreate方法中尝试了以下操作:

super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
getActionBar().hide();  
setContentView(R.layout.viewpager);
两者都可以正常工作,而且操作栏是不可见的。但问题是,我无法使用actionbar消失后留下的空间。我的意思是,如果我想垂直居中布局中的一个小部件,它会计算操作栏覆盖的空间,然后将小部件居中放置在左侧的空间中,因此看起来不居中。以下是xml文件内容:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/background"
    android:gravity="center_vertical" >

    <LinearLayout
        android:layout_centerInParent="true"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">



    <ImageView
        android:id="@+id/imageview_create_db_first_time"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:background="@drawable/data" />
    <TextView 
        android:layout_marginTop="10dp"
        android:layout_gravity="center_horizontal"
        android:id="@+id/textview_create_database"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/create_database"
        android:textSize="15sp"
        android:textColor="@color/white_text"/>
    </LinearLayout>

</RelativeLayout>

有人能帮我吗


谢谢

您的代码很好。我在我的项目中使用了类似的代码。我认为imageview中的margin:top属性使其显示在中心下方

android:layout_marginTop="20dp"

因此,请删除这一行。

您应该使用无标题标志:

requestWindowFeature(Window.FEATURE_NO_TITLE);
或者创建主题并添加:

<item name="android:windowNoTitle">true</item>
true

我不确定这是否是您要找的
this.requestWindowFeature(Window.FEATURE\u NO\u TITLE)你是对的,但实际上我有一个相对论视图,其中包含图像和图像上方的文本视图,该边距应该设置它们之间的边距。编辑的问题谢谢你的警告