Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/188.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在滚动条上显示和隐藏BottomAppBar_Android_Android Layout_Material Components - Fatal编程技术网

Android 在滚动条上显示和隐藏BottomAppBar

Android 在滚动条上显示和隐藏BottomAppBar,android,android-layout,material-components,Android,Android Layout,Material Components,我正在尝试实现BottomAppBar,在这里我将处理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

我正在尝试实现
BottomAppBar
,在这里我将处理
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"/>


我在任何地方都找不到这方面的教程,所以有人在上面实现了解决方案吗?

尝试设置
app:hideOnScroll
,而不设置
app:layout\u behavior
app:layou scrollFlags
。并删除
AppBarLayout
父视图,使
BottomAppBar
只是
协调布局的直接子视图
HideOnScroll不能与ScrollView一起使用,请使用NestedScrollView。

签出问题,它适用于
BottomNavigationView
,但我认为它适用于您。您还应该将内容(在本例中是您的ConstraintLayout)放在NestedScrollView中。这就是CoordinatorLayout可以接收滚动事件并发送到BottomAppBar行为的原因,而BottomAppBar行为将隐藏它。@Cameron,你能分享代码片段以帮助我更好地理解吗?我在片段中有一个RecyclerView inside ConstraintLayout,它位于FrameLayout中的站点。如何在此处使用NestedScrollView?您需要有一个
协调器布局
,将
回收视图
(或实现
NestedScrollingChild
)和
底部AppBar
作为直接子对象。然后您只需在
BottomAppBar
上设置
app:hideOnScroll
,即可启用该功能。这有意义吗?RecyclerView也可以