created the BottomTabActivity and one fragment with the xml file. I connected all this and when creating a normal button in the fragment xml file, it appears in this BottomTab, wherever I place it. I do not know what the trouble is. enter image description here

  MainActivity.xml <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout 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/container" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <android.support.design.widget.BottomNavigationView android:id="@+id/navigation" android:layout_width="0dp" android:layout_height="wrap_content" android:background="?android:attr/windowBackground" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:menu="@menu/navigation" /> </android.support.constraint.ConstraintLayout> MainActivity.class public class MainActivity extends AppCompatActivity { private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener = new BottomNavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(@NonNull MenuItem item) { switch (item.getItemId()) { case R.id.navigation_home: account account = new account(); FragmentManager manager = getSupportFragmentManager(); manager.beginTransaction().replace(R.id.navigation, account, account.getTag()).commit(); return true; case R.id.navigation_dashboard: return true; case R.id.navigation_notifications: return true; } return false; } }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation); navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener); } 

}

  • 3
    Until the telepaths that determine the problem from the screenshot came, attach the markup code to the question - A. Shakhov
  • Attached the page with the markup MainAcivity - fantik
  • And the fragment code? I suspect there is a button to the bottom of the guy, and this fragment with a transparent background is simply OVER the navigation view - iamthevoid
  • In this case, you need to create a container layout, FrameLayout, for example, restrict it from above, to the right and left by parent, below the navigation and put a fragment in it - iamthevoid

1 answer 1

The problem is as follows

Namely, in the line:

 manager.beginTransaction().replace(R.id.navigation, account, account.getTag()).commit(); 

You fill the R.id.navigation container R.id.navigation your fragment that contains this button. Since BottomNavigationView is a successor to FrameLayout , it easily places your fragment with a button in it.

Decision

In MainActivity.xml place the container for your FrameLayout fragments FrameLayout with the BottomNavigationView . Suppose the container has the attribute android:id="@+id/container" .

Then in the code, change the problem line to:

 manager.beginTransaction().replace(R.id.container, account, account.getTag()).commit();