Java 我尝试使用导航抽屉在活动之间切换,而不是片段
下面是我申请的代码。我试着做这件事,但没有发现任何对我有效的东西。如果不变成碎片,我能做什么Java 我尝试使用导航抽屉在活动之间切换,而不是片段,java,android,uinavigationbar,navigation-drawer,Java,Android,Uinavigationbar,Navigation Drawer,下面是我申请的代码。我试着做这件事,但没有发现任何对我有效的东西。如果不变成碎片,我能做什么 public boolean onNavigationItemSelected(MenuItem item) { // Handle navigation view item clicks here. int id = item.getItemId(); if (id == R.id.my_account) { } else if (i
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.my_account) {
} else if (id == R.id.nav_news) {
} else if (id == R.id.nav_live) {
} else if (id == R.id.nav_media) {
} else if (id == R.id.nav_calendar) {
} else if (id == R.id.nav_results) {
} else if (id == R.id.nav_about) {
} else if (id == R.id.nav_shop) {
} else if (id == R.id.nav_social_media) {
} else if (id == nav_fanzone) {
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
将您的onNavigationItemSelected()更改为:
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
switch(item.getItemId()){
case R.id.my_account:
//Do code here
break;
case R.id.nav_news:
//Do code here
break;
case R.id.nav_live:
//Do code here
break;
case R.id.nav_media:
//Do code here
break;
case R.id.nav_calendar:
//Do code here
break;
case R.id.nav_results:
//Do code here
break;
case R.id.nav_about:
//Do code here
break;
case R.id.nav_shop:
//Do code here
break;
case R.id.nav_social_media:
//Do code here
break;
case R.id.nav_fanzone:
//Do code here
break;
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
对于更改活动只需将此添加到所有切换案例中:
Intent intent=new Intent(your_activity.this,your_next_activity.class);
startActivity(intent);
谢谢你的回答,布鲁诺。当我使用导航抽屉时,我会在你的活动中放置什么?thanks@A.Nutley如果导航抽屉位于MainActivity中,则只需将您的_活动更改为MainActivity。此,您的_活动是导航抽屉的父活动。