Java Android Studio:如何将地图附加到NavigationDrawer片段
这是我在这里的第一篇文章,我真的不知道如何开始。所以如果太长,请原谅。。 所以…几天前我开始在Android Studiomy first one上做一个项目…所以我对它了解不多,我还在学习…这是怎么回事…所以它应该有一个地图活动+一个抽屉活动。 我创建了一个地图项目..解决了..创建了一个位置侦听器..所以到目前为止,我的项目有一个简单的地图,在我的当前位置上有一个标记。 然后..我继续我的第二个目标..拥有一个可绘制的活动--右键单击project->new->activity->navigation drawer activity(项目->新建->活动->导航抽屉活动)差不多就是这样,然后,我重写清单,以覆盖我的地图,使抽屉成为第一个: 我很想将我的地图附加到主页按钮/片段上,所以当我按下主页按钮时,它会显示我的地图,当我按下幻灯片时,它会显示这是幻灯片片段 显示 我会把链接放到Git上: 任何帮助都是非常感谢的。如果我提供了很多无用的信息,我会很抱歉的Java Android Studio:如何将地图附加到NavigationDrawer片段,java,android,google-maps,Java,Android,Google Maps,这是我在这里的第一篇文章,我真的不知道如何开始。所以如果太长,请原谅。。 所以…几天前我开始在Android Studiomy first one上做一个项目…所以我对它了解不多,我还在学习…这是怎么回事…所以它应该有一个地图活动+一个抽屉活动。 我创建了一个地图项目..解决了..创建了一个位置侦听器..所以到目前为止,我的项目有一个简单的地图,在我的当前位置上有一个标记。 然后..我继续我的第二个目标..拥有一个可绘制的活动--右键单击project->new->activity->navig
@Override
public boolean onNavigationItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.nav_home){
startActivity(new Intent(MainActivity.this, MapsActivity.class));
}
if (id == R.id.nav_slideshow){
//Here you can put you code
FragmentManager manager = getFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
transaction.add(R.id.container,YOUR_FRAGMENT_NAME,YOUR_FRAGMENT_STRING_TAG);
transaction.addToBackStack(null);
transaction.commit();
}
return true;
}
private AppBarConfiguration mAppBarConfiguration;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
DrawerLayout drawer = findViewById(R.id.drawer_layout);
NavigationView navigationView = findViewById(R.id.nav_view);
// Passing each menu ID as a set of Ids because each
// menu should be considered as top level destinations.
mAppBarConfiguration = new AppBarConfiguration.Builder(
R.id.nav_home, R.id.nav_gallery, R.id.nav_slideshow)
.setDrawerLayout(drawer)
.build();
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
NavigationUI.setupActionBarWithNavController(this, navController, mAppBarConfiguration);
NavigationUI.setupWithNavController(navigationView, navController);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onSupportNavigateUp() {
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
return NavigationUI.navigateUp(navController, mAppBarConfiguration)
|| super.onSupportNavigateUp();
}
@Override
public boolean onNavigationItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.nav_home){
startActivity(new Intent(MainActivity.this, MapsActivity.class));
}
if (id == R.id.nav_slideshow){
//Here you can put you code
FragmentManager manager = getFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
transaction.add(R.id.container,YOUR_FRAGMENT_NAME,YOUR_FRAGMENT_STRING_TAG);
transaction.addToBackStack(null);
transaction.commit();
}
return true;
}