-1

I am trying to get Bottom navigation bar height, because my view height is dynamic which is dependent on navigation bar height.

But issue, In some device i get proper height of navigation bar, and in some device the height comes higher number then what height of navigation bar is visible in device.

Please check my code and screenshots of different devices.

        val resources = context.resources
        val resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android")
        var navHeightBottom = 0
        if (resourceId > 0) {
            navHeightBottom = resources.getDimensionPixelSize(resourceId)
            Logger.d("VideoRollComment", "nav height: $navHeightBottom")
        }

Device Screenshot one which is not correct

Device Screenshot two which is correct

Device Screenshot three which is not correct

1 Answers1

0

Instead of manually calculating the height & setting position by code,

  1. Use '?actionBarSize' attribute to set the height of both tool bar & bottom navigation bar

  2. Use ConstraintLayout to position navigation bar

    <androidx.constraintlayout.widget.ConstraintLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    
      <View
        android:id="@+id/view"
        android:layout_width="0dp"
        android:layout_height="?actionBarSize"
        android:background="#A81414"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent" />
    </androidx.constraintlayout.widget.ConstraintLayout>
    
Heshan Sandeepa
  • 3,388
  • 2
  • 35
  • 45