Android 启用自动隐藏/显示时,BottomNavigationView不显示
我有一个Android 启用自动隐藏/显示时,BottomNavigationView不显示,android,material-design,android-animation,bottomnavigationview,Android,Material Design,Android Animation,Bottomnavigationview,我有一个活动,在它的布局中有一个底部导航视图: <androidx.coordinatorlayout.widget.CoordinatorLayout android:layout_width="match_parent" android:layout_height="match_parent" > <androidx.fragment.app.FragmentConta
活动
,在它的布局中有一个底部导航视图
:
<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>
。我目前使用的是阿披舍克·辛格给出的答案,但问题不是这个
这就是我的问题:想象一下FragA
和FragB
都有RecyclerViews
,但是FragA
的项目较少,导致所有项目都适合屏幕并且不可滚动。现在,当我从FragA
切换到FragB
然后向下滚动时,bottom_导航
会隐藏动画,如果我按下后退按钮,我就看不到bottom_导航
,因为FragA
不可滚动,我无法通过滚动使其可见
我还尝试了在FragA
onResume
事件中使用bottom\u navigation.visibility=View.visibility
,但仍然不起作用。我认为它以某种方式将bottom\u导航
转换为bottom,因此该代码没有帮助
那么我该如何解决这个问题呢?因为这里没有代码的一部分,所以我的解决方案是监听后退按钮:
也许你可以看看这篇文章,这会很有帮助
底部导航视图的可见性也发生了变化。我找到了答案。我没有更改底部导航
的可见性
属性,而是在底部导航视图
上编写了两个用于隐藏/显示它的扩展函数:
private fun BottomNavigationView.showUp() {
animate().setDuration(200L).translationY(0f).withStartAction { visibility = View.VISIBLE }.start()
}
private fun BottomNavigationView.hideDown() {
animate().setDuration(200L).translationY(height.toFloat()).withEndAction { visibility = View.GONE }.start()
}
现在在FragA
的onResume
中,我有以下内容:
override onResume() {
super.onResume()
bottom_navigation.showUp()
}
谢谢,但我已经说过我试过了。可见性更改不起作用这是否回答了您的问题@不,这只是一个自动隐藏/显示底部导航的解决方案。我现在正在用它。