Hello I want equally weight(width) all menu options if i use 4 options menu like 3 option menu
3 Answers
After googling a little bit I found the solution. All you have to do is disable the shift mode
which Android uses to show shifting animation when there are more than 3 tabs in the bottom navigation view.
Use the code given below to disable the shift mode,
import android.support.design.internal.BottomNavigationItemView;
import android.support.design.internal.BottomNavigationMenuView;
import android.support.design.widget.BottomNavigationView;
import android.util.Log;
import java.lang.reflect.Field;
public class BottomNavigationViewHelper {
public static 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);
//noinspection RestrictedApi
item.setShiftingMode(false);
// set once again checked value, so view will be updated
//noinspection RestrictedApi
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);
}
}
}
Apply disableShiftMode
on your BottomNavigationView. It will work.
BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation);
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
BottomNavigationViewHelper.disableShiftMode(navigation);
For more information, follow this Answer How to disable BottomNavigationView shift mode?
Don't forget upvote his answer! :P
Bottom Navigation view is designed in that way to display selected item little big and with text(if given). if you don't want such behavior you can use Tab from design library and set gravity at bottom.
For more you can check documentation - https://material.io/guidelines/components/bottom-navigation.html#bottom-navigation-usage

- 5,979
- 4
- 40
- 55
Why you don't use LinearLayout
with weight=0.25
inside BottomNavigationView

- 403
- 3
- 11