我试图将所有图标居中,我已经通过使用以下代码禁用了切换模式:
/**
* 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,但是它也不起作用。
我的底部导航视图如下:
我正在使用implementation "com.android.support:design:27.0.1"
编辑:
正如您在“布局检查器”中所看到的,图标大小相同,为63x63像素,但选中的图标的Y小5像素。
答案 0 :(得分:0)
从Design Support Library 28.0.0-alpha1开始,您可以使用属性
app:labelVisibilityMode =“未标记”