2

I am trying to use bottom navigation view in my app but I'm having issues getting it to work as it seems to behave differently according to the number of items i am displaying in the bottom navigation view

this is the view when i have only three items in it.

behaves as i want

it displays as i want

but when i make it four the view gets bad

not what i want

it doesn't expand to fit to the edge of my screen it is just positioned at the center of my screen.

below is my activity main layout

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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=".MainActivity">


<android.support.design.widget.AppBarLayout
    android:id="@+id/appBarLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">


    <include
        android:id="@+id/main_app_bar"
        layout="@layout/app_bar_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</android.support.design.widget.AppBarLayout>

<FrameLayout
    android:id="@+id/frame_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />


<android.support.design.widget.BottomNavigationView
    android:id="@+id/navigation"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:layout_alignParentBottom="true"
    app:itemBackground="@color/colorPrimary"
    app:itemIconTint="@color/white"
    app:itemTextColor="@color/white"
    app:menu="@menu/navigation" />

</android.support.design.widget.CoordinatorLayout>
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Eric
  • 157
  • 2
  • 17

3 Answers3

1

Add label visibility mode to you bottom navigation view

<android.support.design.widget.BottomNavigationView
    android:id="@+id/navigation"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    app:labelVisibilityMode="labeled" // this line
    android:background="@color/colorPrimary"
    app:itemBackground="@color/colorPrimary"
    app:itemIconTint="@color/white"
    app:itemTextColor="@color/white"
    app:menu="@menu/navigation" />
Amit Jangid
  • 2,741
  • 1
  • 22
  • 28
1

BottomNavigationView has condition: when there is more than 3 items then use shift mode. Review this answer. Visit

Reva
  • 59
  • 1
  • 1
  • 7
-1

Since you have more than three items you may have to disable shift mode. Please see the anawer in this question How to disable BottomNavigationView shift mode?

teh_raab
  • 384
  • 1
  • 3
  • 21