-1

I am working with BottomNavigationView. Seems everything is okay but i have problem that items are not placed with equal width.

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

This is my menu file.

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">

<item
    android:id="@+id/tab_home_check"
    android:icon="@drawable/ic_home"
    android:title="Home"
    />
<item
    android:id="@+id/tab_rides"
    android:icon="@drawable/ic_road"
    android:title="Rides"
     />
<item
    android:id="@+id/tab_payment"
    android:icon="@drawable/ic_payment"

    android:title="Payment"
     />
<item
    android:id="@+id/tab_profile"
    android:icon="@drawable/ic_profile"
    android:title="Profile"
     />
<item
    android:id="@+id/tab_support"
    android:icon="@drawable/ic_support"
    android:title="Support"
     />
</menu>

And this is the result what i am getting.

enter image description here

So advanced help would be appreciated!

Piyush
  • 395
  • 5
  • 25

2 Answers2

0

Use This Line

app:labelVisibilityMode="labeled"
AskNilesh
  • 63,753
  • 16
  • 113
  • 150
0

Remove the shift mode

@SuppressLint("RestrictedApi")
private fun removeShiftMode(view: BottomNavigationView) {
   val menuView = view.getChildAt(0) as BottomNavigationMenuView
   try {
   val shiftingMode = menuView.javaClass.getDeclaredField("mShiftingMode")
   shiftingMode.isAccessible = true
   shiftingMode.setBoolean(menuView, false)
   shiftingMode.isAccessible = false
   for (i in 0 until menuView.childCount) {
     val item = menuView.getChildAt(i) as BottomNavigationItemView
     item.setShiftingMode(false)
     item.setChecked(item.itemData.isChecked)
   }
   } catch (e: NoSuchFieldException) {
   Log.e("NoSuchFieldException", "Unable to get shift mode field")
   } catch (e: IllegalAccessException) {
   Log.e("IllegalAccessException", "Unable to change value of shift mode")
}

}
Lakhwinder Singh
  • 6,145
  • 4
  • 22
  • 39