【发布时间】:2020-08-18 04:57:33
【问题描述】:
我目前正在开发一个需要创建导航模板的应用程序。我一直在为我需要处理的应用程序微调默认导航模板的外观。但是,有一件事我一直无法找到解决方案,那就是更改应用栏中的文本。它一直说“首页”,但我需要把我的应用程序的标题放在那里。我尝试了几件事,例如:setTitle("App title here") 在 mainActivity 和清单文件中,我还尝试将android:label 中的文本更改为应用程序标题,但我从网上找到的解决方案中没有做任何事情似乎有效。
有什么办法可以解决这个问题并将“主页”文本更改为我的应用程序标题?提前感谢您的任何建议。
注释中要求的 OnCreate 内的代码:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setTitle("Simple Dark Calculator")
setContentView(R.layout.activity_main)
val toolbar: Toolbar = findViewById(R.id.toolbar)
setSupportActionBar(toolbar)
val drawerLayout: DrawerLayout = findViewById(R.id.drawer_layout)
val navView: NavigationView = findViewById(R.id.nav_view)
val navController = findNavController(R.id.nav_host_fragment)
// Passing each menu ID as a set of Ids because each
// menu should be considered as top level destinations.
appBarConfiguration = AppBarConfiguration(setOf(
R.id.nav_home, R.id.nav_gallery, R.id.nav_slideshow), drawerLayout)
setupActionBarWithNavController(navController, appBarConfiguration)
navView.setupWithNavController(navController)
}
【问题讨论】:
-
在
onCreate中向我们展示您的代码,以便我们更好地帮助您。 -
@Armin 更新了我的问题。
-
查看out
标签: android kotlin navigation-drawer android-architecture-navigation android-jetpack-navigation