问题描述
我正在尝试实现BottomAppBar
,在那里我将处理WebView
的导航.
I'm trying to implement BottomAppBar
where I would handle the navigation of a WebView
.
<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"
tools:context=".MainActivity">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
android:id="@+id/web_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<com.google.android.material.bottomappbar.BottomAppBar
android:id="@+id/bottom_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:layout_behavior="com.google.android.material.bottomappbar.BottomAppBar$Behavior"
app:hideOnScroll="true"
app:fabAttached="true"
app:fabAlignmentMode="end"
app:layout_scrollFlags="scroll|enterAlways"/>
</android.support.design.widget.AppBarLayout>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_share"
android:tint="#fff"
app:layout_anchor="@id/bottom_bar"
app:backgroundTint="@color/colorPrimary"/>
一切正常,但是我希望能够在用户分别上下滚动时显示和隐藏BottomAppBar
,就像行为此处.
Everything works fine but I want to be able to show and hide the BottomAppBar
when the users scrolls down and up respectively just as is the behavior here.
我在任何地方都找不到教程,所以有人在上面实现了解决方案吗?
I couldn't find a tutorial on that anywhere so has someone implemented a solution on it?
推荐答案
尝试设置app:hideOnScroll
而不设置app:layout_behavior
或app:layout_scrollFlags
.并删除AppBarLayout
父视图,使BottomAppBar
只是CoordinatorLayout
的直接子代.
Try settting app:hideOnScroll
without setting app:layout_behavior
or app:layout_scrollFlags
. And remove the AppBarLayout
parent view so the BottomAppBar
is just a direct child of the CoordinatorLayout
.
这篇关于在滚动条上显示和隐藏BottomAppBar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!