When I click on an icon it doesn't change color unless I click it again, it goes to the activity but only the first icon remains highlighted. I have to click it again for the icon to change color. What is wrong with my code?
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
} }