【发布时间】:2021-01-30 10:42:11
【问题描述】:
这是配置BottomNavigationView导航的常规方式:
val appBarConfiguration = AppBarConfiguration(setOf(R.id.navigation_home, R.id.navigation_months, R.id.navigation_due_date_calculator))
setupActionBarWithNavController(navController, appBarConfiguration)
navView.setupWithNavController(navController)
但是,如果你想为一个按钮调用一个函数而不是打开一个片段,会发生什么?
我试过这个:
navView.setOnNavigationItemSelectedListener {
when (it.itemId){
R.id.navigation_other_useful_apps -> {
Toast.makeText(applicationContext, "Other Useful Apps", Toast.LENGTH_SHORT).show()
true
}
else -> true
}
}
问题是当我添加该方法时,导航不再起作用。如何在一项上调用函数,而在其他项上使用AppBarConfiguration?
【问题讨论】:
标签: android kotlin bottomnavigationview android-bottomnavigationview