Search code examples
androidxmlnavigationbottomnavigationview

Button Nav bar height is unexpected after changing navigation mode to bottom navigation in real device


i am working on android project.Showing perfect on gestures modeThe button nav bar is showing perfect when i enable the gesture navigation in device but it height becomes too large when i switch back to the button navigation in device.It becomes like that When i set the custom height like 70 dp then also it is working perfect on gesture mode but it collpase up and icon do not visible this time not label on button navigation mode.Here is my code:-

 <?xml version="1.0" encoding="utf-8"?>
<layout 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">


    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/main"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".view.admin.AdminHome">


        <androidx.fragment.app.FragmentContainerView
            android:id="@+id/adminFragmentContainerView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            android:layout_marginBottom="?attr/actionBarSize"
            />
        <androidx.coordinatorlayout.widget.CoordinatorLayout
            android:id="@+id/cor"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"
            >

            <com.google.android.material.bottomappbar.BottomAppBar
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintBottom_toBottomOf="parent"
                android:layout_gravity="bottom"
                >

                <com.google.android.material.bottomnavigation.BottomNavigationView
                    android:id="@+id/bNav"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_alignParentBottom="true"
                    app:elevation="20dp"
                    android:background="@android:color/transparent"
                    app:itemActiveIndicatorStyle="@style/App.Custom.Indicator"
                    app:itemIconSize="25dp"
                    app:itemIconTint="@color/bottom_nav_background_item"
                    app:itemTextColor="@color/bottom_nav_background_item"
                    app:labelVisibilityMode="selected"
                    app:layout_behavior="@string/hide_bottom_view_on_scroll_behavior"
                    app:menu="@menu/b_nav"
                    />


            </com.google.android.material.bottomappbar.BottomAppBar>

        </androidx.coordinatorlayout.widget.CoordinatorLayout>

    </androidx.constraintlayout.widget.ConstraintLayout>
</layout>

i want that it should work on both mode either it is navigation mode or gestures mode.


Solution

  • The issue is in your main activity file. You just need to set the bottom padding to 0, like this:

    ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, 0)
            insets
    }