想要使用item跳转页面
比如让item的id为nav_camera的跳转到main.xml,方法怎么写?希望有大佬告知
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
//HOME页面右上角menu菜单
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.
MenuInflater inflater_item = getMenuInflater();
inflater_item.inflate(R.menu.main, null);
switch (item.getItemId()){
case R.id.add_contact:
Toast.makeText(this, "123", Toast.LENGTH_SHORT).show();
break;
case R.id.add_whitelist:
Toast.makeText(this, "456", Toast.LENGTH_SHORT).show();
break;
}
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_camera) {
// Handle the camera action
} 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) {
}