[英]Stop refreshing the bottom navigation bar fragments
I have a bottom navigation bar with 5 items. 我有一个包含5个项目的底部导航栏。 I want the last button to show a "More" menu. 我希望最后一个按钮显示“更多”菜单。 (Hence it should act as a button and not get into a selected state). (因此,它应充当按钮,而不应进入选定状态)。
For this I'm keeping the last selected item id from the navigation bar and when a menu item is clicked setting the navigation item to the last selected item as follows. 为此,我保留了导航栏中的最后选择的项目ID,并在单击菜单项时将导航项目设置为最后选择的项目,如下所示。
menu_item_1_layout.setOnTouchListener { view, motionEvent ->
bottomSheetBehaviour.state = BottomSheetBehavior.STATE_HIDDEN
navigation.selectedItemId = lastSelectedItemId // views are refreshed here
true
}
My problem is how to stop the refreshing the last selected view(since it's already visible) when navigation item is set again. 我的问题是,当再次设置导航项时,如何停止刷新最后一个选定的视图(因为它已经可见)。 Since the menu is a BottomSheet, the view refresh is visible as a blinking. 由于菜单是BottomSheet,因此视图刷新以闪烁的形式显示。 Or is there a better way to do this? 还是有更好的方法来做到这一点?
Ok. 好。 I found out that this behavior was because I'm always setting the fragment without checking the current selected fragment. 我发现此行为是因为我总是在不检查当前选定片段的情况下设置片段。 When I added a check it works correctly. 当我添加支票时,它可以正常工作。
private val mOnNavigationItemSelectedListener = BottomNavigationView.OnNavigationItemSelectedListener { item ->
if (item.itemId == lastSelectedItemId) { // added this
return@OnNavigationItemSelectedListener true
}
when (item.itemId) {
R.id.navigation_home -> {
val fragment = TestFragment()
supportFragmentManager.beginTransaction()
.replace(frame.id, fragment)
.commit()
lastSelectedItemId = item.itemId
return@OnNavigationItemSelectedListener true
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.