我有一个CoordinatorLayout
其中包含一个BottomNavigationView
and an AppBarLayout
with a ToolBar
在它里面。 (这BottomNavigationView
不在里面AppBarLayout
,因为这样做打破了BottomNavigationView
).
我需要显示/隐藏AppBarLayout
和BottomNavigationView
以编程方式,当某些事件发生时(例如在片段的onResume
),到目前为止我已经成功设置appBarLayout.setExpanded(true, true)
为了显示/隐藏 AppBar,但我不知道如何对BottomNavigationView
,因为它没有任何方法来显示/隐藏自身。
我的行为BottomNavigationView
is app:layout_behavior="@string/hide_bottom_view_on_scroll_behavior"
,在布局xml中设置。如何在代码中引用此行为以管理其展开/折叠状态?
该代码会向上滑动协调器布局内部的底部导航,并具有 HideBottomViewOnScrollBehavior。
如果您使用 findViewById 只需将其替换为每个binding.
val layoutParams = binding.bottomNavigation.layoutParams as CoordinatorLayout.LayoutParams
val bottomViewNavigationBehavior = layoutParams.behavior as HideBottomViewOnScrollBehavior
bottomViewNavigationBehavior.slideUp(binding.bottomNavigation)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)