의도를 사용하려고하지만 탐색 용 서랍에서 작동하지 않습니다. 네이티브 Menuitem (3 점)에서만 작동했지만 Navigation Drawer에서 사용하고 싶습니다.메뉴 항목에서 활동 열기
아무도 도와 줄 수 있습니까?
@Override
public boolean onOptionsItemSelected(MenuItem item){
if (mToggle.onOptionsItemSelected(item)){
return true;
}
return super.onOptionsItemSelected(item);
}
public boolean onNavigationItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.menu_one) {
Intent intent = new Intent(this, Activity1.class);
startActivity(intent);
} else if (id == R.id.menu_two) {
Intent intent = new Intent(this, Activity2.class);
startActivity(intent);
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawerLayout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
ID의 참조가 맞습니까? 이는 탐색 서랍에 의도를 사용하는 방법이기 때문입니다. 따라서 내비게이션 서랍 메뉴의 ID를 확인하십시오. –
@AndroidGeek 예, Android 스튜디오에서는 오류가 없으며 정상적으로 apk를 생성합니다. 하지만 애플 리케이션에서 작동하지 않습니다. –
전체 활동 코드를 게시하십시오. onNavigationItemSelected가 호출 되었습니까? – ABDevelopers