I am new to android and I am trying to make an app with more than 3 elements in the bottom navigation bar. I am able to display them but they are getting clustered at the end and only three are visible properly. Here is my code:
<android.support.design.widget.BottomNavigationView
android:id="@+id/bottomNavigation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:elevation="15dp"
android:layout_gravity="bottom"
android:layout_alignParentBottom="true"
app:menu="@menu/bottom_nav_items" />
Here is the image of the view: This is the snapshot
I am stuck please help..
You can use below method for not getting clustered menu items. You have to call this method in onCreate method passing BottomNavigationView.
// Method for disabling ShiftMode of BottomNavigationView
private void disableShiftMode(BottomNavigationView view) {
BottomNavigationMenuView menuView = (BottomNavigationMenuView) view.getChildAt(0);
try {
Field shiftingMode = menuView.getClass().getDeclaredField("mShiftingMode");
shiftingMode.setAccessible(true);
shiftingMode.setBoolean(menuView, false);
shiftingMode.setAccessible(false);
for (int i = 0; i < menuView.getChildCount(); i++) {
BottomNavigationItemView item = (BottomNavigationItemView) menuView.getChildAt(i);
item.setShiftingMode(false);
// set once again checked value, so view will be updated
item.setChecked(item.getItemData().isChecked());
}
} catch (NoSuchFieldException e) {
Log.e("BNVHelper", "Unable to get shift mode field", e);
} catch (IllegalAccessException e) {
Log.e("BNVHelper", "Unable to change value of shift mode", e);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With