I am trying to implement a bottom navigation with using Jetpack Navigation. In addition to fragments in the bottom navigation, there is another fragment which I designed it to be the starting destination.
The problem is that when I start the app, my starting destination (Fragment Play) is displayed on the screen but the item in bottom navigation starts as checked (Scoreboard) which I don't want it to be checked at the start.
My MainActivity codes;
class MainActivity : AppCompatActivity() {
private lateinit var binding: ActivityMainBinding
private lateinit var navController: NavController
private lateinit var appBarConfiguration: AppBarConfiguration
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
val navHostFragment = supportFragmentManager
.findFragmentById(R.id.nav_host_fragment) as NavHostFragment
navController = navHostFragment.findNavController()
appBarConfiguration = AppBarConfiguration(
setOf(R.id.scoreboardFragment, R.id.playFragment, R.id.settingsFragment)
)
binding.apply {
setSupportActionBar(toolbar)
setupActionBarWithNavController(navController, appBarConfiguration)
bottomNavigation.setupWithNavController(navController)
bottomNavigation.background = null
}
}
I tried to use bottomNavigation.menu[0].isChecked = false
and bottomNavigation.menu.setGroupCheckable(0, false, true)
from the question but setGroupCheckable()
also prevents the tint color on selected item and setting isChecked = false
didn't do anything or I them it wrong.
So is there any other way to fix this from removing the starting destination from the FAB and adding it to the bottom navigation as an additional item? Because this design is more convenient and cool for my app in my opinion.
Thanks in advance.