Skip to content

Instantly share code, notes, and snippets.

@princessdharmy
Created November 21, 2020 19:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save princessdharmy/277d7beaa18233cb5a4c48910c08084d to your computer and use it in GitHub Desktop.
Save princessdharmy/277d7beaa18233cb5a4c48910c08084d to your computer and use it in GitHub Desktop.
class HomeActivity : BaseActivity() {
private lateinit var navController: NavController
private lateinit var appBarConfiguration: AppBarConfiguration
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setSupportActionBar(binding.toolbar)
initBinding()
}
private fun initBinding() {
// Finding the Navigation Controller
val navHostFragment =
supportFragmentManager.findFragmentById(R.id.fragNavHost) as NavHostFragment
navController = navHostFragment.navController
// Setting Navigation Controller with the BottomNavigationView
NavigationUI.setupWithNavController(binding.bottomNavigation, navHostFragment.navController)
//Setting Up ActionBar with Navigation Controller
appBarConfiguration =
AppBarConfiguration(setOf(R.id.todayFixtureFragment, R.id.competitionsFragment))
setupActionBarWithNavController(navController, appBarConfiguration)
// This helps to customise the toolbar i.e the back button
navController.addOnDestinationChangedListener { _, destination, _ ->
if(destination.id == R.id.viewPager) {
supportActionBar?.setHomeAsUpIndicator(R.drawable.ic_arrow_back_black_24dp)
}
}
}
/**
* This enables click listener on the back button
*/
override fun onSupportNavigateUp() =
findNavController(R.id.fragNavHost).navigateUp(appBarConfiguration)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment