gpt4 book ai didi

Android Kotlin 底部导航栏

转载 作者:行者123 更新时间:2023-11-29 18:52:36 27 4
gpt4 key购买 nike

我使用底部导航栏(默认情况下为 xx_activity 底部),但我遇到了问题。当我点击该项目时它没问题, Activity 很好但 Activity 的项目没有改变......

import android.content.Intent
import android.os.Bundle
import android.support.design.widget.BottomNavigationView
import android.support.v7.app.AppCompatActivity
import kotlinx.android.synthetic.main.activity_grammaire.*

class GrammaireActivity : AppCompatActivity() {

private val mOnNavigationItemSelectedListener=BottomNavigationView.OnNavigationItemSelectedListener { item ->
when (item.itemId) {
R.id.navigation_grammaire -> {
val intent = Intent(this,GrammaireActivity::class.java)
startActivity(intent)
return@OnNavigationItemSelectedListener true
}
R.id.navigation_situations -> {
val intent = Intent(this,SituationsActivity::class.java)
startActivity(intent)
return@OnNavigationItemSelectedListener true
}
R.id.navigation_lexiquefrsa -> {
val intent = Intent(this,LexiqueFrSaActivity::class.java)
startActivity(intent)
return@OnNavigationItemSelectedListener true
}
R.id.navigation_lexiquesafr -> {
val intent = Intent(this,LexiqueSaFrActivity::class.java)
startActivity(intent)
return@OnNavigationItemSelectedListener true
}
R.id.navigation_infos -> {
val intent = Intent(this,InfosActivity::class.java)
startActivity(intent)
return@OnNavigationItemSelectedListener true
}
}
false
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_grammaire)

navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener)
}

}

最佳答案

我认为建议使用带底部导航的 fragment ,而不是 Activity 。使用 onClick,您可以将当前 fragment 替换为点击所标识的 fragment 。

关于Android Kotlin 底部导航栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50623354/

27 4 0