繁体   English   中英

停止刷新底部导航栏片段

[英]Stop refreshing the bottom navigation bar fragments

我有一个包含5个项目的底部导航栏。 我希望最后一个按钮显示“更多”菜单。 (因此,它应充当按钮,而不应进入选定状态)。

为此,我保留了导航栏中的最后选择的项目ID,并在单击菜单项时将导航项目设置为最后选择的项目,如下所示。

menu_item_1_layout.setOnTouchListener { view, motionEvent ->
        bottomSheetBehaviour.state = BottomSheetBehavior.STATE_HIDDEN
        navigation.selectedItemId = lastSelectedItemId // views are refreshed here
        true
    }

我的问题是,当再次设置导航项时,如何停止刷新最后一个选定的视图(因为它已经可见)。 由于菜单是BottomSheet,因此视图刷新以闪烁的形式显示。 还是有更好的方法来做到这一点?

好。 我发现此行为是因为我总是在不检查当前选定片段的情况下设置片段。 当我添加支票时,它可以正常工作。

 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM