我试图让 ALL 图标居中,我已经使用以下代码禁用了移动模式:
/**
* This is done to remove the shift animation introduced by Android on the bottom navigation view
* https://stackoverflow.com/a/41690461/4243027
*/
@SuppressLint("RestrictedApi")
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);
item.setPadding(0,15,0,0);
// 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);
}
}
并设置标题为“”
android:title=""
我还尝试执行以下操作 https://stackoverflow.com/a/40234361/4243027但它也不起作用。
我的底部导航 View 是这样的:
我正在使用实现“com.android.support:design:27.0.1”
编辑:
正如您在布局检查器中看到的那样,图标大小相同,均为 63x63 像素,但选中图标的 Y 轴小了 5 像素。
最佳答案
从设计支持库 28.0.0-alpha1 开始,您可以使用该属性
app:labelVisibilityMode="未标记"
关于android - 中心底部导航栏图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51611638/