I am trying to change the navigation icon when opening the settings fragment using
CodePudding user response:
Try this
navController.addOnDestinationChangedListener { _, destination, _ ->
Log.d(TAG, "addOnDestinationChangedListener: " destination.id)
if (destination.id == R.id.settingsFragment) {
drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED)
if (drawerLayout.isDrawerOpen(GravityCompat.START)) {
drawerLayout.closeDrawer(GravityCompat.START)
}
binding.toolbar.setNavigationOnClickListener { //do whatever you want here
navController.navigateUp()
}
} else {
drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED)
binding.toolbar.setNavigationOnClickListener{
drawerLayout.openDrawer(GravityCompat.START)
}
}
override fun showBackIcon() {
supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setDisplayShowHomeEnabled(true)
binding.toolbar.setNavigationIcon(R.drawable.ic_arrow_back_24)
}
and remove showHamburgerIcon
& ActionBarDrawerToggle
codes