Hello Everyone我是初学者,刚刚开始在android中编码我发现了一个关于如何制作导航抽屉的教程。
教程链接: - http://www.android4devs.com/2015/06/navigation-view-material-design-support.html
我确实想知道如果我点击导航抽屉中的选项有任何方法,新活动将打开它将是一个很好的帮助回答。
提前谢谢
答案 0 :(得分:2)
mDrawerList.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
switch (position) {
case 1:
Intent intent= new Intent(CurrentActivity.this,AnotherActivity.class);
startActivity(intent);
break;
case 2:
...
default:
break;
}
}
});
答案 1 :(得分:2)
我正在使用
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.nav_cinema) {
Intent cinemaIntent = new Intent(this, CinemaActivity.class);
startActivity(cinemaIntent);
} else if (id == R.id.nav_tv) {
} else if (id == R.id.nav_tvseason) {
} else if (id == R.id.nav_share) {
} else if (id == R.id.nav_send) {
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
它对我有用:) (它是默认的android导航抽屉菜单)
答案 2 :(得分:1)
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.activity_about) {
Intent activity_about = new Intent(this, AboutActivity.class);
startActivity(activity_about);
} else if (id == R.id.nav_gallery) {
} else if (id == R.id.nav_slideshow) {
} else if (id == R.id.nav_manage) {
} else if (id == R.id.nav_share) {
} else if (id == R.id.nav_send) {
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
}
答案 3 :(得分:0)
作为新实现,您可以使用引入NavigationView
类和DrawerLayout
模式的全新设计支持库。查看the release notes了解详情。
答案 4 :(得分:0)
if (id == R.id.activity_about) {
Intent activity_about = new Intent(this, AboutActivity.class);
startActivity(activity_about);