【发布时间】:2018-12-17 13:55:48
【问题描述】:
我查看了stackoverflow,找到了关于如何从默认bottom navigation. 中删除动画的解决方案
现在我需要从底部导航中删除标题。我在底部导航 xml 文件的标题中设置了空字符串,但它不会改变图像的位置。 我正在使用 v27
删除文本后,我需要将图像居中在 bottom navigation. 中。
这是我的代码。
//OnCreate
BottomNavigationViewHelper.removeShiftMode(bottomNavigationView);
MainActivity 中的静态类
public static class BottomNavigationViewHelper {
@SuppressLint("RestrictedApi")
public static void removeShiftMode(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("BottomNav", "Unable to get shift mode field", e);
} catch (IllegalAccessException e) {
Log.e("BottomNav", "Unable to change value of shift mode", e);
}
}
}
【问题讨论】:
标签: java android android-layout android-fragments android-intent