title: Setting title of the toolbar when a navigation item menu is clicked
body: <p>In my app I have the following navigationview.</p>
  
  <p><a href="https://i.stack.imgur.com/sNnZ1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sNnZ1.png" alt="my app"></a></p>
  
  <p>So when the user click the menu item Καλώς ήρθες(meaning welcome in Greek),I want the this to be shown in the toolbar. This is my code for the navigationview.</p>
  
  <pre><code>public class Welcome extends AppCompatActivity {
  private NavigationView navigationView;
  private DrawerLayout drawerLayout;
  private SessionManager session;
  Toolbar toolbar;
  private int mIconSize;
  private String username;
  
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_welcome);
  
      session = new SessionManager(getApplicationContext());
  
  
  
      SharedPreferences userName = PreferenceManager.getDefaultSharedPreferences(this);
      //UserId = userName.getString("id","");
      username = userName.getString("user_name", "");
  
  
  
      toolbar = (Toolbar)findViewById(R.id.toolbar);
      setSupportActionBar(toolbar);
  
      drawerLayout = (DrawerLayout)findViewById(R.id.drawer_layout);
  
      if (savedInstanceState == null) {
          //Restore the fragment's instance and geo coordinates!
          //homeFragment = (FragmentHome) getSupportFragmentManager().getFragment(savedInstanceState, "mContent");
          setSelected(R.id.welcome);
      }else{
          //profileFragment = (FragmentProfile) fm2.findFragmentByTag(PROFILE_FRAGMENT);
  
      }
      ActionBarDrawerToggle adt = new ActionBarDrawerToggle(this,drawerLayout,toolbar,
              R.string.open_drawer,R.string.close_drawer){
          @Override
          public void onDrawerClosed(View drawerView) {
              super.onDrawerClosed(drawerView);
          }
  
          @Override
          public void onDrawerOpened(View drawerView) {
              super.onDrawerOpened(drawerView);
          }
      };
  
      drawerLayout.addDrawerListener(adt);
      adt.syncState();
      navigationView = (NavigationView)findViewById(R.id.navigation_view);
      navigationView.setBackgroundColor(getResources().getColor(R.color.navigation_bg_color));
      navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
          @Override
          public boolean onNavigationItemSelected(MenuItem item) {
              drawerLayout.closeDrawers();
              boolean result = setSelected(item.getItemId());
              return result;
          }
      });
  
      View v = navigationView.getHeaderView(0);
      TextView t = (TextView)v.findViewById(R.id.username);
      t.setText(username);
  }
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      MenuInflater inflater = getMenuInflater();
      inflater.inflate(R.menu.log_out, menu);
      return true;
  }
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
      switch (item.getItemId()) {
          case R.id.log_out:
  
              logoutUser();
              return true;
      }
      return super.onOptionsItemSelected(item);
  }
  private void logoutUser() {
      session.setLogin(false);
  
      // Launching the login activity
      Intent intent = new Intent(Welcome.this, MainActivity.class);
      startActivity(intent);
      finish();
  }
  public boolean setSelected(int selected) {
      switch (selected){
          case R.id.welcome:
              WelcomeFragment welcomeFragment = new WelcomeFragment();
              FragmentManager fm1 = getSupportFragmentManager();
              FragmentTransaction fragmentTra1 = fm1.beginTransaction();
              fragmentTra1.replace(R.id.content,welcomeFragment);
              //fragmentTra1.addToBackStack("added");
  
              fragmentTra1.commit();
          return true;
          case R.id.general:
              GeneralFragment generalFragment= new GeneralFragment();
              FragmentManager fm2 = getSupportFragmentManager();
              FragmentTransaction fragmentTra2 = fm2.beginTransaction();
              fragmentTra2.replace(R.id.content,generalFragment);
              //fragmentTra1.addToBackStack("added");
  
              fragmentTra2.commit();
              return true;
          case R.id.announcements:
              AnnouncementsFragment announcementsFragment= new AnnouncementsFragment();
              FragmentManager fm3 = getSupportFragmentManager();
              FragmentTransaction fragmentTraSubOne = fm3.beginTransaction();
              fragmentTraSubOne.replace(R.id.content,announcementsFragment);
              //fragmentTra1.addToBackStack("added");
  
              fragmentTraSubOne.commit();
              return true;
          case R.id.sub_one:
              NewsFragment newsFragment= new NewsFragment();
              FragmentManager fm4 = getSupportFragmentManager();
              FragmentTransaction fragmentTraSubTwo = fm4.beginTransaction();
              fragmentTraSubTwo.replace(R.id.content,newsFragment);
              //fragmentTra1.addToBackStack("added");
  
              fragmentTraSubTwo.commit();
              return true;
          case R.id.sub_two:
              FanClubFragment fanClubFragment= new FanClubFragment();
              FragmentManager fm5 = getSupportFragmentManager();
              FragmentTransaction fragmentTraSubThree = fm5.beginTransaction();
              fragmentTraSubThree.replace(R.id.content,fanClubFragment);
              //fragmentTra1.addToBackStack("added");
              fragmentTraSubThree.commit();
              return true;
      }
  
      return false;
  }
  public static Intent newIntent(Context context) {
  
      return new Intent(context,MainActivity.class);
  }
  @Override
  public void onBackPressed() {
      if(isNavDrawerOpen()){
          closeDrawerLayout();
      }else {
          super.onBackPressed();
      }
  }
  
  public boolean isNavDrawerOpen() {
      return drawerLayout!=null &amp;&amp; drawerLayout.isDrawerOpen(GravityCompat.START);
  }
  private void closeDrawerLayout(){
      if(drawerLayout != null){
          drawerLayout.closeDrawer(GravityCompat.START);
      }
  }
  @Override
  public boolean onKeyDown(int keyCode, KeyEvent event)
  {
      return (keyCode == KeyEvent.KEYCODE_BACK ? true :    
    super.onKeyDown(keyCode, event));
   }
  }
  </code></pre>
  
  <p>Any ideas?</p>
  
  <p>Thanks,</p>
  
  <p>Theo.</p>