Jetpack navigation with navigation drawer not display back button and title given in the mobile_navigation.xml on child fragment in androidx

Need to use both these functions

NavigationUI.setupWithNavController (toolbar, navController, drawer_layout)
NavigationUI.setupWithNavController(nav_view,navController)

You need to use NavigationUI.setupActionBarWithNavController()

  • Sets up the ActionBar returned by AppCompatActivity.getSupportActionBar() for use with a NavController.

  • By calling this method, the title in the action bar will automatically be updated when the destination changes (assuming there is a valid label).

  • The actionBar will also display the Up button when you are on a non-root destination. Call navigateUp(DrawerLayout, NavController) to handle the Up button

SAMPLE CODE

For Kotlin

NavigationUI.setupActionBarWithNavController(this, navHost.navController)

For Java

NavigationUI.setupActionBarWithNavController(this, navController.getNavController());

EDIT

Don't forgot to override onSupportNavigateUp() method

fun onSupportNavigateUp(): Boolean {
   // return navHost.navController.navigateUp() || super.onSupportNavigateUp()
    return NavigationUI.navigateUp(drawer, navHost.navController) || super.onSupportNavigateUp()
}

EDIT 2

To use with navigation drawer You need to use NavigationUI.setupWithNavController()

  • By calling this method, the title in the Toolbar will automatically be updated when the destination changes (assuming there is a valid label).

For Kotlin

NavigationUI.setupWithNavController(toolbar, navController, drawer_layout)

For Java

NavigationUI.setupWithNavController(toolbar, navController.getNavController(),drawer_layout);