override fun initListener() {
//        设置tab切换监听
        bottomBar.setOnNavigationItemSelectedListener {
            val transaction = supportFragmentManager.beginTransaction()
            FragmentUtil.fragmentUtil.getFragment(it.itemId)?.let { it1 ->
                transaction.replace(
                    R.id.container,
                    it1, it.itemId.toString()
                )
            }
            transaction.commitNow()
            return@setOnNavigationItemSelectedListener true
        }

    }

注:

  • setOnNavigationItemSelectedListener 是点击未选择的item后的回调,返回的boolean是决定是否启用选中效果或者放大效果(按一次有效果
  • setOnNavigationItemReselectedListener 是如果已经是选中状态后,在点击一次后的回调(第一场为选中,再按一次才有效果