[英]Bottom navigation icon only changing color when clicked twice?
當我點擊一個圖標時,它不會改變顏色,除非我再次點擊它,它會進入活動,但只有第一個圖標保持突出顯示。 我必須再次單擊它才能使圖標更改顏色。 我的代碼有什么問題?
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
} }
您正在使用活動。 使用片段。 我認為它會得到解決。
您為每個項目使用不同的活動。
您必須通過以下方式處理活動中的選定項目:
navigationBar.setSelectedItemId(R.id.nav_explore)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.