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

标签 java android android-toolbar android-coordinatorlayout android-collapsingtoolbarlayout

我想实现一个折叠布局并尝试了这段代码,但它提供了额外的空间。我在主要 Activity 中有一个工具栏,但在配置文件 fragment 中,我通过(“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>

崩溃之前 enter image description here

折叠后 enter image description here

最佳答案

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

enter image description here

关于java - 如何删除工具栏上方的空间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59755740/

相关文章:

java - 迭代列表对象内的对象

Android onActivityResult(来自 MediaStore.ACTION_IMAGE_CAPTURE)无法获取 Galaxy S5 上的数据

android - 使用 Intents 打开最近写入的文件

android - 向上滚动时折叠工具栏图像消失

java - 从 native 迁移到 EclipseLink 持久性

java - BouncyCasSTLe RSA 无法转换 android

java - 单击图像时播放声音

android - 工具栏中占用剩余空间的搜索栏

android - 使用协调器布局以编程方式隐藏工具栏

java - 循环图像,java gui?