Home » Android » Android BottomNavigationView evenly spaced icons

Android BottomNavigationView evenly spaced icons

Posted by: admin June 15, 2020 Leave a comment

Questions:

I have a BottomNavigationView with five items. The default behavior is to only show the label of the selected item and the spacing between all five items differs depending on what item is selected.

I would like a bottom bar more simular to a UITabBar on iOS. Is this possible with BottomNavigationView or can you recommend some other library that solves this?

How to&Answers:

You just need to disable the shift mode:
How to disable BottomNavigationView shift mode?

When you have more than 3 tabs, the shift mode is enabled by default.
This can only be set to disabled by tricky method using Reflection now.

Answer:

There are loads of libraries out there but you can check this and this out.

Anyway, a screenshot of your UI would’ve been better to query the default behavior.

Answer:

UPDATE

You also need to update proguard configuration file (e.g. proguard-rules.pro), code above uses reflection and won’t work if proguard obfuscate the mShiftingMode field.

-keepclassmembers class android.support.design.internal.BottomNavigationMenuView { 
    boolean mShiftingMode; 
}