我正在尝试使用选项卡布局在我的应用程序中实现折叠工具栏行为。我想在折叠模式下隐藏工具栏,只在折叠模式下显示选项卡布局,在正常模式下显示选项卡布局,直到折叠为止我想显示带有应用程序标题的工具栏。目前,它在折叠模式下按我想要的方式工作,我只想添加一个隐藏在折叠模式下的工具栏。
我的代码
<?xml version="1.0" encoding="utf-8"?>
<layout 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">
<data>
</data>
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="@+id/htab_maincontent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/htab_appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="@+id/htab_collapse_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"
app:titleEnabled="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:background="@color/greyprofile"
android:padding="16dp">
<!-- android:background="@drawable/circularbordersolid"-->
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/profilepic"
android:layout_width="150dp"
android:layout_height="150dp"
android:scaleType="centerCrop"
android:src="@drawable/hey" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:fontFamily="@font/proximanovaregular"
android:gravity="center"
android:text="Name User"
android:textColor="#424242"
android:textSize="21sp"
android:textStyle="bold" />
</RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/proximanovaregular"
android:text="Username"
android:textColor="#424242"
android:gravity="center"
android:textSize="14sp" />
</LinearLayout>
<Button
android:id="@+id/editProfileBtn"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:paddingBottom="10dp"
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#757575"
android:text="Edit Profile"
android:gravity="center"
android:textAllCaps="false"
android:textSize="16sp" />
</LinearLayout>
<!-- <androidx.appcompat.widget.Toolbar-->
<!-- android:id="@+id/htab_toolbar"-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="?attr/actionBarSize"-->
<!-- android:layout_gravity="top"-->
<!-- app:layout_collapseMode="pin"-->
<!-- app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>-->
<!-- android:layout_marginBottom="48dp"-->
</com.google.android.material.appbar.CollapsingToolbarLayout>
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"/>
<!-- android:background="@drawable/circularbordersolid"-->
<!-- app:tabIndicatorColor="@android:color/white"-->
<!-- app:tabSelectedTextColor="@android:color/white"-->
</com.google.android.material.appbar.AppBarLayout>
<androidx.viewpager2.widget.ViewPager2
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/pager"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</layout>
最佳答案
您应该从 app:layout_scrollFlags
中删除 exitUntilCollapsed
所以,就这样做 app:layout_scrollFlags="scroll|snap"
关于android - 如何在折叠模式下隐藏工具栏并在正常模式下显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67811468/