2

I have been trying to add BottomNavigationView to a screen. Normally it works as expected but when the keyboard is visible in the screen the height of the BottomNavigationView gets increased unexpectedly.

What I want is to fix the height so that it sticks with the keyboard. There should not be any gaps between BottomNavigationView and Keyboard.

I have added code and screenshot to help you understand my problem.

<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">


    <androidx.coordinatorlayout.widget.CoordinatorLayout
        android:id="@+id/coordinator_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true">

       <!-- Other views -->

        <com.google.android.material.bottomnavigation.BottomNavigationView
            android:id="@+id/bottomNav"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            app:menu="@menu/bottom_navigation_menu" />


    </androidx.coordinatorlayout.widget.CoordinatorLayout>

    <!-- Other views -->

</androidx.drawerlayout.widget.DrawerLayout>

wrong BottomNavigationView height.

zoha131
  • 1,758
  • 2
  • 16
  • 18

1 Answers1

1

remove fitsSystemWindows in CoordinatorLayout:

<androidx.coordinatorlayout.widget.CoordinatorLayout
    android:id="@+id/coordinator_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"> 

and change windowSoftInputMode of your activity in manifest file :

<activity
        android:name=".YourActivity"
        android:windowSoftInputMode="adjustResize">
Kasım Özdemir
  • 5,414
  • 3
  • 18
  • 35
  • thanks for your answer. It is fixed now. But I have no clue what happened under the hood and why I was getting this kind of behavior. Can you please explain to me? Or point me to any blog/documentation from where I can get the knowledge? – zoha131 May 16 '20 at 15:36
  • https://medium.com/androiddevelopers/why-would-i-want-to-fitssystemwindows-4e26d9ce1eec. – Kasım Özdemir May 16 '20 at 16:06