<com.mohamadreza7565.cbottomnav.CBottomNavigation
android:id="@+id/activityHome_bottomBar"
android:layout_width="match_parent"
android:layout_height="75dp"
android:layout_alignParentBottom="true"
app:menuChildView="@menu/menu" />
private var currentNavController: LiveData<NavController>? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
if (savedInstanceState == null) {
setupBottomNavigationBar()
}
}
override fun onRestoreInstanceState(savedInstanceState: Bundle) {
super.onRestoreInstanceState(savedInstanceState)
setupBottomNavigationBar()
}
private fun setupBottomNavigationBar() {
val bottomNavigationView = findViewById<CBottomNavigation>(R.id.activityHome_bottomBar)
val navGraphIds = listOf(
R.navigation.home,
R.navigation.setting,
)
val controller = bottomNavigationView.setupWithNavController(
navGraphIds = navGraphIds,
fragmentManager = supportFragmentManager,
containerId = R.id.nav_host_container,
intent = intent
)
currentNavController = controller
}
override fun onSupportNavigateUp(): Boolean {
return currentNavController?.value?.navigateUp() ?: false
}
bottomNavigationView.setOnTabItemClickListener(object : CBottomNavigation.OnTabItemClickListener {
override fun onTabClicked(item: MenuItem, reselect: Boolean) {
when (item.itemId) {
R.id.home -> {
// Change fragment or activity
}
R.id.setting -> {
// Change fragment or activity
}
}
}
})