我使用的是协调器布局。而且,我有一个像上图这样的布局。并且,标题/文本显示在那里。当我位于该布局的顶部时(或者,当工具栏未显示时),我想隐藏该文本。而且,当工具栏显示时,我想显示该文本。怎么做?
这是我的 xml
代码:
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:background="@android:color/white">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="@+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:toolbarId="@+id/toolbar">
<androidx.appcompat.widget.AppCompatImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:scaleType="fitXY"
android:src="@drawable/banner"
app:layout_collapseMode="parallax" />
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="@style/AppTheme.PopupOverlay"
app:layout_scrollFlags="scroll|enterAlways"
android:text="Name" />
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
我试图检查 isToolbarShown 与否。
if(toolbar.isShown()){
Toast.makeText(this, "Showing", Toast.LENGTH_SHORT).show(); //I don't know what to do. And, I added it in `onCreate` method. So, it only check ones. How to check while scrolling anywhere?
}else{
Toast.makeText(this, "not showing", Toast.LENGTH_SHORT).show();
}