Created
November 21, 2020 19:28
-
-
Save princessdharmy/277d7beaa18233cb5a4c48910c08084d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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