Java 如何删除工具栏上方的空间?

Java 如何删除工具栏上方的空间?,java,android,android-toolbar,android-coordinatorlayout,android-collapsingtoolbarlayout,Java,Android,Android Toolbar,Android Coordinatorlayout,Android Collapsingtoolbarlayout,我想实现一个折叠布局,并尝试了这段代码,但它提供了额外的空间。我在主活动中有一个工具栏,但在概要文件片段中,我通过(“GlobalVar.toolbar.hide()”删除了它,全局变量已全部全局使用。) 即使在崩溃之后,我也有一些重叠 collapse.xml <?xml version="1.0" encoding="utf-8"?> <androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android

我想实现一个折叠布局,并尝试了这段代码,但它提供了额外的空间。我在主活动中有一个工具栏,但在概要文件片段中,我通过(“GlobalVar.toolbar.hide()”删除了它,全局变量已全部全局使用。) 即使在崩溃之后,我也有一些重叠

collapse.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="300dp"
        android:fitsSystemWindows="true"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <com.google.android.material.appbar.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:expandedTitleMarginStart="48dp"
            app:layout_scrollFlags="scroll|exitUntilCollapsed|snap">

            <ImageView
                android:id="@+id/header"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/toolbar_background"
                android:fitsSystemWindows="true"
                android:scaleType="centerCrop"
                app:layout_collapseMode="parallax"/>

            <androidx.appcompat.widget.Toolbar
                android:id="@+id/anim_toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
        </com.google.android.material.appbar.CollapsingToolbarLayout>
    </com.google.android.material.appbar.AppBarLayout>


</androidx.coordinatorlayout.widget.CoordinatorLayout>

崩溃后

我测试了您的代码,但工具栏上方没有任何空间,这是我的输出:


试试这是我的答案你想要什么?