当我点击一个图标时,它不会改变颜色,除非我再次点击它,它会进入活动,但只有第一个图标保持突出显示。我必须再次单击它才能使图标更改颜色。我的代码有什么问题?
class ProfileActivity : BaseActivity(){
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_profile)
val navigationBar = findViewById<BottomNavigationView>(R.id.navigation_bar)
navigationBar.setOnNavigationItemSelectedListener(navigation_bar)
}
private val navigation_bar = BottomNavigationView.OnNavigationItemSelectedListener { item ->
when (item.itemId) {
R.id.nav_profile -> {
// startActivity(Intent(this@ProfileActivity, ProfileActivity::class.java))
return@OnNavigationItemSelectedListener true
}
R.id.nav_explore -> {
startActivity(Intent(this@ProfileActivity, ExploreActivity::class.java))
return@OnNavigationItemSelectedListener true
}
R.id.nav_store -> {
startActivity(Intent(this@ProfileActivity, StoreActivity::class.java))
return@OnNavigationItemSelectedListener true
}
R.id.nav_board -> {
startActivity(Intent(this@ProfileActivity, BoardActivity::class.java))
return@OnNavigationItemSelectedListener true
}
}
false
} }