Search code examples
androidbottomnavigationview

BottomNavigationView is visible even if view is top of it


I have screen with 3 main parts

  • toolbar
  • homeContaner(will host fragments of BottomNavigationView)
  • mainContainer (host splash screen or any screen that take full of screen)

when replace mainContainer with splash BottomNavigationView is also shown I tried to add background color to mainContainer and found that BottomNavigationView is on Top of mainContainer

also tried to add elevation to mainContainer but got no new results

Screen shots enter image description here

full code

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".feature.home_Activity.HomeActivity">

    <androidx.appcompat.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toTopOf="parent"
        android:background="?attr/colorPrimary"
        android:minHeight="?attr/actionBarSize"
        app:titleTextColor="@android:color/white"/>

    <FrameLayout
        android:id="@+id/homeContainer"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="@id/dummy"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/toolbar" />

    <View
        android:id="@+id/dummy"
        android:layout_width="match_parent"
        android:layout_height="@dimen/_10sdp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="@id/navigation" />

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/navigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:elevation="1dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:menu="@menu/navigation" />

    <FrameLayout
        android:id="@+id/mainContainer"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:elevation="10dp"
        android:background="#ffaaff"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />


</androidx.constraintlayout.widget.ConstraintLayout>

Solution

  • Wrap BottomNavigationView with LinearLayout solved the problem

    <?xml version="1.0" encoding="utf-8"?>
    <androidx.constraintlayout.widget.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:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".feature.home_Activity.HomeActivity">
    
        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="?attr/colorPrimary"
            android:minHeight="?attr/actionBarSize"
            app:layout_constraintTop_toTopOf="parent"
            app:titleTextColor="@android:color/white" />
    
        <FrameLayout
            android:id="@+id/homeContainer"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_constraintBottom_toBottomOf="@id/dummy"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/toolbar" />
    
        <View
            android:id="@+id/dummy"
            android:layout_width="match_parent"
            android:layout_height="@dimen/_10sdp"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="@id/navigationContainer" />
    
        <androidx.appcompat.widget.LinearLayoutCompat
            android:id="@+id/navigationContainer"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_constraintBottom_toBottomOf="parent">
    
            <com.google.android.material.bottomnavigation.BottomNavigationView
                android:id="@+id/navigation"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@drawable/bn_bg"
                app:elevation="1dp"
                app:itemBackground="@drawable/bn_item__bg"
                app:itemIconTint="@color/secondaryTextColor"
                app:itemTextColor="@color/primaryTextColor"
                app:layout_constraintBottom_toBottomOf="parent"
                app:menu="@menu/navigation" />
    
    
        </androidx.appcompat.widget.LinearLayoutCompat>
    
    
        <FrameLayout
            android:id="@+id/mainContainer"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:elevation="10dp"
    
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />
    
    
    </androidx.constraintlayout.widget.ConstraintLayout>