gpt4 book ai didi

java - 底部导航图标仅在单击两次后才会更改颜色?

转载 作者:行者123 更新时间:2023-12-02 13:16:40 26 4
gpt4 key购买 nike

当我单击一个图标时,除非再次单击它,否则它不会改变颜色,它将转到 Activity 中,但只有第一个图标保持突出显示。我必须再次单击它才能更改颜色。我的代码有什么问题?

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
} }

最佳答案

您正在使用 Activity 。使用片段。我认为它将解决。

关于java - 底部导航图标仅在单击两次后才会更改颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63056438/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com