你好我正在制作一个应用程序,我无法在布局中一起实现导航抽屉和谷歌地图活动。我想在导航抽屉中添加地图活动,就像ola app的工作方式一样。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
Intent intent9 = new Intent(this, Maps.class);
startActivity(intent9);// Adding map activity
}
@Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.map, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.nav_scheduled) {
Intent intent5 = new Intent(this, ScheduledTimings.class);
startActivity(intent5);
}
else if (id == R.id.nav_contact) {
Intent intent6 = new Intent(this, EmergencyContact.class);
startActivity(intent6);
}
else if (id==R.id.nav_feedback){
Intent intent10 = new Intent(this, Feedback.class);
startActivity(intent10);
}
else if (id == R.id.nav_about) {
Intent intent7 = new Intent(this, About.class);
startActivity(intent7);
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
答案 0 :(得分:0)
你有什么打算做的?在上面的代码中,我只看到了一个抽屉实现,那么Map呢?
我建议你这样做:
在主活动中实现抽屉,这里使用片段并在片段中插入MapView。
应该有效。