单击导航抽屉菜单中的项目后打开新 Activity
Open new Activity after click item in navigation drawer menu
大家好我是初学者,刚开始在 android 中编码,我找到了一个关于如何制作导航抽屉的教程。
教程Link:- http://www.android4devs.com/2015/06/navigation-view-material-design-support.html
我想知道有没有什么办法,如果我点击导航抽屉中的选项,一个新的 activity 将打开它对回答有很大帮助。
提前致谢
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;
}
}
});
作为新的实现,您可以使用引入了 NavigationView
class 和 DrawerLayout
模式的全新设计支持库。查看 the release notes 了解更多信息。
我正在使用
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 抽屉式导航菜单)
大家好我是初学者,刚开始在 android 中编码,我找到了一个关于如何制作导航抽屉的教程。
教程Link:- http://www.android4devs.com/2015/06/navigation-view-material-design-support.html
我想知道有没有什么办法,如果我点击导航抽屉中的选项,一个新的 activity 将打开它对回答有很大帮助。
提前致谢
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;
}
}
});
作为新的实现,您可以使用引入了 NavigationView
class 和 DrawerLayout
模式的全新设计支持库。查看 the release notes 了解更多信息。
我正在使用
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 抽屉式导航菜单)