I am following the codelab https://developer.android.com/codelabs/kotlin-android-training-add-navigation/index.html#9, and I use the following code to wire up the drawer:
class MainActivity : AppCompatActivity() {
private lateinit var drawerLayout : DrawerLayout
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@Suppress("UNUSED_VARIABLE")
val binding = DataBindingUtil.setContentView<ActivityMainBinding>(this, R.layout.activity_main)
drawerLayout = binding.drawerLayout
val navController = findNavController(R.id.myNavHostFragment)
// To support up action and also the title, the third parameter is optional and is used
// for the hamburger menu for drawer.
NavigationUI.setupActionBarWithNavController(this, navController, drawerLayout)
// show the navigation drawer
NavigationUI.setupWithNavController(binding.navView, navController)
}
override fun onSupportNavigateUp(): Boolean {
val navController = findNavController(R.id.myNavHostFragment)
// this is for the hamburger menu
return NavigationUI.navigateUp(navController, drawerLayout)
}
}
When the initial fragment is shown, the hamburger is shown as expected:
However, after I selected on one of the item from the drawer, e.g. About, it becomes a back/up button:
How to keep using the hamburger button instead of having it changed to an up button?
The full code from the codelab is here: https://github.com/google-developer-training/android-kotlin-fundamentals-apps/tree/master/AndroidTriviaNavigation

