title: Overlap occurs when switching fragments with the Bottom Navigation Activity
body: <p>I created a new project with the Bottom Navigation Activity. When I try to switch fragments through the buttons on the bottom navigation bar, the other fragment always overlaps the fragment started by default.
  I set up four fragments to switch.</p>
  <p>IndexActivity.java</p>
  <pre><code>public class IndexActivity extends AppCompatActivity {
  
  private FragmentManager fragmentManager;
  private FragmentTransaction transaction;
  
      @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_index);
      BottomNavigationView navView = findViewById(R.id.nav_view);
      // Passing each menu ID as a set of Ids because each
      // menu should be considered as top level destinations.
      AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(
              R.id.message_id, R.id.friends_id, R.id.news_id,R.id.mine_id)
              .build();
      NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
      NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
      NavigationUI.setupWithNavController(navView, navController);
  
      fragmentManager= getSupportFragmentManager();
      transaction= fragmentManager.beginTransaction();
      transaction.replace(R.id.nav_host_fragment, new MessageFragment());
      transaction.commit();
  
      navView.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
  }
  
  private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener=new BottomNavigationView.OnNavigationItemSelectedListener() {
      @Override
      public boolean onNavigationItemSelected(@NonNull MenuItem item) {
          switch (item.getItemId()){
              case R.id.message_id:
                  fragmentManager= getSupportFragmentManager();
                  transaction= fragmentManager.beginTransaction();
                  transaction.replace(R.id.nav_host_fragment, new MessageFragment());
                  transaction.commit();
                  return true;
              case R.id.friends_id:
                  fragmentManager= getSupportFragmentManager();
                  transaction= fragmentManager.beginTransaction();
                  transaction.replace(R.id.nav_host_fragment, new FriendsFragment());
                  transaction.commit();
                  return true;
              case R.id.news_id:
                  fragmentManager= getSupportFragmentManager();
                  transaction= fragmentManager.beginTransaction();
                  transaction.replace(R.id.nav_host_fragment, new NewsFragment());
                  transaction.commit();
                  return true;
              case R.id.mine_id:
                  fragmentManager= getSupportFragmentManager();
                  transaction= fragmentManager.beginTransaction();
                  transaction.replace(R.id.nav_host_fragment, new MineFragment());
                  transaction.commit();
                  return true;
          }
          return false;
      }
  };
  </code></pre>
  <p>activity_index.xml</p>
  <pre><code>&lt;androidx.constraintlayout.widget.ConstraintLayout 
  xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
  xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
  android:id=&quot;@+id/container&quot;
  android:layout_width=&quot;match_parent&quot;
  android:layout_height=&quot;match_parent&quot;
  android:paddingTop=&quot;?attr/actionBarSize&quot;&gt;
  
  &lt;fragment
      android:id=&quot;@+id/nav_host_fragment&quot;
      android:name=&quot;androidx.navigation.fragment.NavHostFragment&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;match_parent&quot;
      app:defaultNavHost=&quot;true&quot;
      app:layout_constraintBottom_toTopOf=&quot;@id/nav_view&quot;
      app:layout_constraintLeft_toLeftOf=&quot;parent&quot;
      app:layout_constraintRight_toRightOf=&quot;parent&quot;
      app:layout_constraintTop_toTopOf=&quot;parent&quot;
      app:navGraph=&quot;@navigation/mobile_navigation&quot; &gt;
  
  &lt;/fragment&gt;
  
  &lt;com.google.android.material.bottomnavigation.BottomNavigationView
      android:id=&quot;@+id/nav_view&quot;
      android:layout_width=&quot;0dp&quot;
      android:layout_height=&quot;wrap_content&quot;
      android:layout_marginEnd=&quot;0dp&quot;
      android:layout_marginStart=&quot;0dp&quot;
      android:background=&quot;?android:attr/windowBackground&quot;
      app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
      app:layout_constraintLeft_toLeftOf=&quot;parent&quot;
      app:layout_constraintRight_toRightOf=&quot;parent&quot;
      app:menu=&quot;@menu/bottom_nav_menu&quot; /&gt;
  
  &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;
  </code></pre>
  <p><a href="https://i.stack.imgur.com/5S1eP.png" rel="nofollow noreferrer">enter image description here</a></p>
  <p>I would really appreciate if someone could help me! Thank You!</p>