Attempting to use a bottom nav view, the standard view provided by android. The first time I click on any fragment, it's a SUPER delayed UI reaction time (about 2 seconds until the ripple, item selection update, and new fragment show) It's only the first time I switch to any fragment, after that, it behaves as expected.
I found a similar question already on here, but there were zero suggestions or answers. See that post here
Find below the logic I user for switching the fragments.
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
bottom_nav_bar.inflateMenu(R.menu.bottom_nav_bar_menu)
bottom_nav_bar.selectedItemId = R.id.nav_summary
bottom_nav_bar.setOnNavigationItemSelectedListener { menuItem ->
when (menuItem.itemId) {
R.id.nav_1-> startFragment1()
R.id.nav_2 -> startFragment2()
else -> startFragment3()
}
true
}
}
fun startFragment1() = replaceFragment(Fragment1(), "TAG1")
fun startFragment2() = replaceFragment(Fragment2(), "TAG2")
fun startFragment3() = replaceFragment(Fragment3(), "TAG3")
private fun replaceFragment(fragment: Fragment, fragmentTag: String) {
fragmentManager.beginTransaction()
.setCustomAnimations(R.animator.fade_in, R.animator.fade_out)
.replace(R.id.fragment_container, fragment, fragmentTag)
.commit()
}