Search code examples
androidkotlinbottomnavigationviewandroid-bottomnav

Android BottomNavigation showes "Up Button" when navigating between tabs


I've sat up a bottom navigation bar in my app. When I enable action bar with navController, the up button shows when navigating between tabs.

[Fig.1: up button is gone when I'm in home destination]

enter image description here


[Fig.2: up button show up when navigation between tabs]

enter image description here

It goes away when i remove this line in MainActivity but then I lose up button for the whole app:

setUpActionBarWithNavCotroller(navController)

How can i make "Up Button" disapper from bottom navigation tabs?


Solution

  • Your Tasks and Categories are top-level destinations. So, you have to assign them to navController. Here's the official documentation.

    Step 1:

    Initialize AppBarConfiguration as follow

    val appBarConfiguration = AppBarConfiguration(
            topLevelDestinationIds = setOf(R.id.tasksFragment, R.id.categoriesFragment)
        )
    

    Step 2:

    Assign them to navController with your Toolbar

    findViewById<Toolbar>(R.id.toolbar)
            .setupWithNavController(navController, appBarConfiguration)
    

    or ActionBar

    setupActionBarWithNavController(navController, appBarConfiguration)