【发布时间】:2019-11-20 23:32:02
【问题描述】:
当我尝试在 java 上使用 android 导航组件时。它不适用于开箱即用的导航抽屉。除了从导航抽屉导航到片段之外,我能够执行所有操作。 我正在做一个项目,我需要快速摆脱困境,并想用我更有经验的 java 来完成它。有没有人能够破解这个?
implementation 'androidx.navigation:navigation-fragment:2.1.0'
implementation 'androidx.navigation:navigation-ui:2.1.0'
MainActivity onCreate
rootLayout = findViewById(R.id.drawer_layout);
drawerLayout = findViewById(R.id.drawer_layout);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
NavHostFragment navHostFragment = (NavHostFragment)getSupportFragmentManager().findFragmentById(R.id.nav_host_fragment);
navController = navHostFragment.getNavController();
mAppBarConfiguration = new AppBarConfiguration.Builder(navController.getGraph())
.setDrawerLayout(drawerLayout)
.build();
drawerLayout = findViewById(R.id.drawer_layout);
//setup navigation
NavigationView navigationView = findViewById(R.id.nav_view);
NavigationUI.setupWithNavController(navigationView, navController);
mAppBarConfiguration = new AppBarConfiguration.Builder(
R.id.nav_home, R.id.nav_claims, R.id.nav_products,R.id.nav_deliveries, R.id.nav_quotes,
R.id.nav_policies, R.id.nav_payment,R.id.nav_about,R.id.nav_contact)
.setDrawerLayout(drawerLayout)
.build();
//setup action bar
NavigationUI.setupActionBarWithNavController(this, navController, mAppBarConfiguration);
PS:mobile_navigation.xml和activity_main_drawer.xml上的id是一样的。所以没有问题。
【问题讨论】:
标签: java android kotlin android-architecture-navigation