onCreate(){
initialize nav controller
val navController = this.findNavController(R.id.myNavHostFragment)
NavigationUI.setupActionBarWithNavController(this,navController)
}
// enable upbutton
override fun onSupportNavigateUp(): Boolean {
val navController = this.findNavController(R.id.myNavHostFragment)
return navController.navigateUp()
}
now create a navigation.xml under resources folder. Open design and add your first fragment as destination. While creating fragments make sure to uncheck create layout file, include fragment factory methods, include interface callbacks.