1. First Method
2. Second Method
3. Third Method
Java
// Drawer item Click event navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected (@NonNull MenuItem item) { if (item.getItemId() == R.id.mHome) { Toast.makeText( context: MainActivity.this, text "This is home", Toast.LENGTH_SHORT).show(); }else if (item.getItemId() == R.id.Share) { Toast.makeText(context: MainActivity.this, text "share", Toast.LENGTH_SHORT).show(); } return false; } });
Java
// Drawer item Click event NavButton.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(@NonNull MenuItem item) { int id = item.getItemId(); if (id == R.id.home ){ } else if (id == R.id.myTrips){ Intent myIntent = new Intent(MainActivity.this,MyTripsActivity.class); startActivity(myIntent); } else if (id == R.id.alarts) { Intent myIntent = new Intent(MainActivity.this,NotificationActivity.class); startActivity(myIntent); } else { Intent myIntent = new Intent(MainActivity.this,ProfileActivity.class); startActivity(myIntent); } return true; } }); NavButton.setSelectedItemId(R.id.home);
Java
// Drawer item Click event NavButton.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.menu_all_users: // complete later case R.id.menu_account_setting: Intent settingIntent = new Intent(MainActivity.this, SettingActivity.class); startActivity(settingIntent); finish(); case R.id.menu_log_out: auth.signOut(); Intent loginIntent = new Intent(MainActivity.this , LoginActivity.class); } return true; } }); NavButton.setSelectedItemId(R.id.home);