title: How to coordinate a Navigation Drawer with a Buttom Navigation View
body: <p>I'm fairly new to android dev. I'm checking the material design library and I've implemented a navigation drawer with a bottom navigation to navigate easily through fragments. Both components work just fine but I don't how to coordinate the navigation with both components. For example when a fragment is toggled on the navigation drawer it changed the layout but the button navigation selected item is not changed with it.</p>
  
  <p>How can I solve this issue and link both components to work with each other and sync the changed selected item?</p>
  
  <p><img src="https://i.imgur.com/ceGAxeWl.png" alt="selected Item in bottom navigation drawer: notification"></p>
  
  <p><img src="https://i.imgur.com/Gmrp7XQl.png" alt="selected Item in navigation drawer: annonce"></p>
  
  <p>This is what my java file looks like and here's link for the whole project on GitHub: <a href="https://github.com/mreek/NavigationDrawer" rel="nofollow noreferrer">https://github.com/mreek/NavigationDrawer</a></p>
  
  <p>Thank you in advance.</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
  
      private DrawerLayout drawer;
      private TextView appBarTV;
      private static final String TAG = "MyActivity";
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          Intent intent= new Intent(this,IntroActivity.class);
          startActivity(intent);
  
          drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
          appBarTV = findViewById(R.id.appbar_text_view);
  
          ImageButton menuRight = findViewById(R.id.leftRight);
          menuRight.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  if (drawer.isDrawerOpen(GravityCompat.START)) {
                      drawer.closeDrawer(GravityCompat.START);
                  } else {
                      drawer.openDrawer(GravityCompat.START);
                  }
              }
          });
  
          NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
          navigationView.setNavigationItemSelectedListener(this);
  
          BottomNavigationView bottomNavigationView = (BottomNavigationView)findViewById(R.id.navigation);
  
          bottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
              @Override
              public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                  Fragment selectedFragment = null;
                  switch (item.getItemId()) {
                      case R.id.action_item1:
                          selectedFragment = MainFragment.newInstance();
                          break;
                      case R.id.action_item2:
                          selectedFragment = AccountFragment.newInstance();
                          break;
                      case R.id.action_item3:
                          selectedFragment = SellFragment.newInstance();
                          break;
                      case R.id.action_item4:
                          selectedFragment = ChatFragment.newInstance();
                          break;
                      case R.id.action_item5:
                          selectedFragment = NotificationFragment.newInstance();
                          break;
                  }
                  FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
                  transaction.replace(R.id.f_container, selectedFragment);
                  transaction.commit();
                  return true;
              }
          });
  
          FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
          transaction.replace(R.id.f_container, MainFragment.newInstance());
          transaction.commit();
      }
  
      @Override
      public void onBackPressed() {
          DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
          if (drawer.isDrawerOpen(GravityCompat.START)) {
              drawer.closeDrawer(GravityCompat.START);
          } else {
              super.onBackPressed();
          }
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          getMenuInflater().inflate(R.menu.main, menu);
          return true;
      }
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          int id = item.getItemId();
          if (id == R.id.action_settings) {
              return true;
          }
          return super.onOptionsItemSelected(item);
      }
  
      @Override
      public boolean onNavigationItemSelected(MenuItem item) {
          drawer.closeDrawers();
          FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
  
          int id = item.getItemId();
  
          if (id == R.id.nav_camera) {
              MainFragment fragment = new MainFragment();
              ft.replace(R.id.f_container, fragment);
              ft.commit();
          } else if (id == R.id.nav_gallery) {
              //appBarTV.setText("Fragment With Tabs");
              ChatFragment fragment = new ChatFragment();
              ft.replace(R.id.f_container, fragment);
              ft.commit();
          } else if (id == R.id.nav_slideshow) {
              AccountFragment fragmentTab = new AccountFragment();
              ft.replace(R.id.f_container, fragmentTab);
              ft.commit();
          } else if (id == R.id.nav_share) {
              Toast.makeText(this, "Partager", Toast.LENGTH_SHORT).show();
          } else if (id == R.id.nav_send) {
              Toast.makeText(this, "Rate 5 stars", Toast.LENGTH_SHORT).show();
          }
  
          DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
          drawer.closeDrawer(GravityCompat.START);
          return true;
      }
  }
  </code></pre>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      xmlns:tools="http://schemas.android.com/tools"
      android:id="@+id/drawer_layout"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:fitsSystemWindows="true"
      tools:openDrawer="start"&gt;
  
      &lt;RelativeLayout
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:orientation="vertical"&gt;
  
          &lt;include layout="@layout/app_bar_main" /&gt;
  
          &lt;FrameLayout
              android:id="@+id/f_container"
              android:layout_width="match_parent"
              android:layout_height="match_parent" /&gt;
  
          &lt;android.support.design.widget.BottomNavigationView
              android:id="@+id/navigation"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:layout_alignParentBottom="true"
              android:layout_marginBottom="3dp"
              android:background="@color/white"
              app:itemIconTint="@color/blue"
              app:itemTextColor="@color/blue"
              app:menu="@menu/bottom_navigation_items" /&gt;
  
      &lt;/RelativeLayout&gt;
  
      &lt;android.support.design.widget.NavigationView
          android:id="@+id/nav_view"
          android:layout_width="wrap_content"
          android:layout_height="match_parent"
          android:layout_gravity="start"
          android:fitsSystemWindows="true"
          app:headerLayout="@layout/nav_header_main"
          app:menu="@menu/activity_main_drawer"
          app:itemTextColor="@color/black"/&gt;
  &lt;/android.support.v4.widget.DrawerLayout&gt;
  </code></pre>