添加滚动行为后默认隐藏BottomNavigationView

问题描述 投票:0回答:1

我的片段中有以下主要布局和recyclerview。我面临的问题是底部导航视图默认隐藏,只有当我向下滚动导航视图时才会出现。

在向下滚动before scrolling down之后向下滚动bottomnavigationview出现after scrolling down

我面临的另一个问题是,在向下滚动并更改片段后,工具栏会消失

content_home.xml

<RelativeLayout 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"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context=".activity.HomeActivity"
    tools:showIn="@layout/activity_home">

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/navigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:background="?android:attr/windowBackground"
        app:itemIconTint="@drawable/nav_item_foreground"
        app:itemTextColor="@drawable/nav_item_foreground"
        app:layout_behavior="@string/hide_bottom_view_on_scroll_behavior"
        app:menu="@menu/navigation" />



    <FrameLayout
        android:id="@+id/fragment_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/navigation" />


</RelativeLayout>

这是主要的活动布局activity_home.xml

<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"
    >

    <com.google.android.material.appbar.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/appBar"
        android:theme="@style/AppTheme.AppBarOverlay">

        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

    </com.google.android.material.appbar.AppBarLayout>

    <include
        layout="@layout/content_home" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>
android android-support-library androidx
1个回答
0
投票

你的content_home.xml有一个问题你在app:layout_behavior="@string/hide_bottom_view_on_scroll_behavior"使用BottomNavigationView

这就是它发生的原因。

删除hide_bottom_view_on_scroll_behaviorfrom app:layout_behavior

© www.soinside.com 2019 - 2024. All rights reserved.