是setOnNavigationItemReselectedListener
的现在被弃用了。要在 Google 底部导航上执行点击操作,您必须在您的活动/片段中使用bottomNavigation.setOnItemSelectedListener(this)
和扩展NavigationBarView.OnItemSelectedListener
bottomNavigation.setOnItemSelectedListener(this)
然后覆盖onNavigationItemSelected(item: MenuItem)
示例Kotlin
:
bottomNavigation.setOnItemSelectedListener(this)
override fun onNavigationItemSelected(item: MenuItem): Boolean {
when(item.itemId){
R.id.your_menu_id->{
Toast.makeText(this,"Click",Toast.LENGTH_SHORT).show()
}
///
}
return true
}
或者
bottomNavigationView.setOnItemSelectedListener{
when (it.itemId) {
R.id.your_menu_id-> {
Toast.makeText(this,"Click",Toast.LENGTH_SHORT).show()
return@setOnItemSelectedListener true
}
///
}
false
}
并用于重选使用bottomNav.setOnItemReselectedListener(this)
和扩展NavigationBarView.OnItemReselectedListener
和覆盖 onNavigationItemReselected(item: MenuItem)