【发布时间】:2019-08-18 18:48:24
【问题描述】:
是否可以在每个片段都有自己的工具栏的单个活动应用程序中使用 Android 导航组件/图形?
此外,容器活动有一个导航抽屉,需要使用工具栏和导航控制器进行设置,但在创建活动时我还没有工具栏。
我正在使用这段代码(在 onCreate 中调用)
private fun setupNavigation() {
// val toolbar = findViewById<Toolbar>(R.id.toolbar);
// setSupportActionBar(toolbar);
// supportActionBar!!.setDisplayHomeAsUpEnabled(true);
// supportActionBar!!.setDisplayShowHomeEnabled(true);
val drawerLayout = findViewById<DrawerLayout>(R.id.drawer_layout);
val navigationView = findViewById<NavigationView>(R.id.drawer_navigation_view);
val navController = Navigation.findNavController(this, R.id.navigation_host_fragment);
NavigationUI.setupActionBarWithNavController(this, navController, drawerLayout)
NavigationUI.setupWithNavController(navigationView, navController)
navigationView.setNavigationItemSelectedListener(this)
}
但由于当时我没有工具栏,它会引发错误(在空对象上调用 ActionBar.setTitle)。
是否有可能,或者在这种情况下我需要放弃使用导航组件的想法?
【问题讨论】:
标签: android navigation-drawer android-navigation android-architecture-navigation android-navigationview