我有一个Activity,它的布局中有一个BottomNavigationView:
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<androidx.fragment.app.FragmentContainerView
android:id="@+id/nav_host"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:layout_behavior="@string/hide_bottom_view_on_scroll_behavior"
app:menu="@menu/menu_home_bottom_navigation"
/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>我的bottom_avigation用片段来改变nav_host FragmentContainerView。所有这些片段都有NestedScrollView或RecyclerView,因为有了app:layout_behavior="@string/hide_bottom_view_on_scroll_behavior",bottom_navigation会自动隐藏/显示在滚动下来/滚动向上。
我看到了这个问题:在卷轴上隐藏/显示bottomNavigationView。我目前正在使用Abhishek Singh给出的答案,但问题不是这个。
这是我的问题:假设FragA和FragB都有RecyclerViews,但是FragA的条目少了,导致所有的项目都适合屏幕而不能滚动。现在,当我从FragA切换到FragB,然后切换到scrollDown时,bottom_navigation会用动画隐藏起来,如果我按下后退按钮,就不能再看到bottom_navigation了,而且由于FragA是不可滚动的,所以不能通过滚动使其可见。
我也尝试过bottom_navigation.visibility = View.Visible in FragA onResume事件,但仍然不起作用。我认为它以某种方式将bottom_navigation转换到了底部,正因为如此,这段代码没有帮助。
那我该怎么解决这个问题呢?
发布于 2020-09-13 21:13:34
由于您的代码中没有任何部分,所以我的解决方案是在back按钮上侦听:
也许你可以看看这篇文章,这会有帮助的。
这改变了BottomNavigationView的可见性。
https://stackoverflow.com/questions/63874110
复制相似问题