Android:屏幕顶部不需要的白框(工具栏?)

Android: Unwanted White Box at Top of Screen (toolbar?)

如何去掉 android 视图顶部的白框?我在我的代码中看不到我调用创建工具栏的东西的任何地方,我也没有自己编写代码。它也存在于视图之上,而不是其中。我猜 xml 文件的设计视图中有一些设置可以切换它?提前致谢!

** 我还应该包括它仅在此 activity 上,我的其他活动顶部没有这个白色条。此外,actionbar 是白色汽车上方的蓝色细条,因此任何涉及操作 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="@drawable/bucket"
    android:theme="@+id/BucketTheme2"
    android:backgroundTint="#70FFFFFF"
    android:backgroundTintMode="src_over">

<TableLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TableRow>
        <TextView
            android:id="@+id/textView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:paddingBottom="5dp"
            android:paddingTop="100dp"
            android:text="Find a place to go around you!"
            android:textColor="#ff000000"
            android:textSize="18dp" />
    </TableRow>

    <TableRow
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <Button
            android:id="@+id/button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:onClick="randomButtonPressed"
            android:text="RANDOMIZE"
            android:textSize="20dp" />
    </TableRow>

    <TableRow
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <Button
            android:id="@+id/bucketBtn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:onClick="bucketButtonPressed"
            android:text="Bucket List"
            android:textSize="20dp" />

    </TableRow>

    <TableRow
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <Button
            android:id="@+id/searchLocationBtn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:onClick="searchButtonPressed"
            android:text="Search by Location"
            android:textSize="20dp" />

    </TableRow>

</TableLayout>

</RelativeLayout>

编辑 2:style.xml BucketTheme2 的代码如下(我最初没有 post 因为它只设置颜色):

<style name="BucketTheme2" parent="android:Theme.Holo.Light.DarkActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

尝试

 requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
        WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.main);

应该在setContentView之前

添加以下主题到style.xml

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

然后将此主题设置为manifest中的activity:

  <activity
      android:name=".MainActivity"
      android:theme="@style/AppTheme.NoActionBar"/>

更新:您还可以按如下方式设置主题:

<style name="BucketTheme2" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

希望这对您有所帮助。

在 style.xml

中添加 NoActionBar 样式
<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>
    <item name="windowNoTitle">true</item>
    <item name="windowActionBar">false</item>
    <item name="android:windowFullscreen">false</item>
    <item name="android:windowContentOverlay">@null</item>
</style>

并将此主题添加到清单中的 activity,

<activity android:name=".YourActivity"
        android:theme="@style/AppTheme"
        >
    </activity>

将清单中的 activity 主题更改为 Theme.AppCompat.Light.NoActionBar,您应该被排序

设置应用程序主题或 Manifest.xml 中的 activity 以删除操作栏:

android:theme="@android:style/Theme.Holo.Light.NoActionBar"

或者在onCreate方法中的Activity中添加如下代码并导入android.support.v7.app.ActionBar:

ActionBar actionBar = getSupportActionBar();
actionBar.hide();

试试你的风格

<style name="BucketTheme2" parent="android:Theme.Holo.Light.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>

我 运行 在使用 Android 工作室已经设置的模板项目时遇到了同样的问题。我注意到在我更改为 *.NoActionBar 主题后,activity_main.xml 文件顶部出现了不必要的填充。如果您删除 android:paddingTop="?attr/actionBarSize" 它应该会消失。

    <?xml version="1.0" encoding="utf-8"?>
    <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingTop="?attr/actionBarSize"></androidx.constraintlayout.widget.ConstraintLayout>