底部导航栏上的按钮不在其位置上

时间:2018-02-01 22:05:42

标签: android android-layout bottomnavigationview

我正在尝试创建一个底部导航栏,但按钮正在向右移动

enter image description here

如何修复底部导航栏中的视图看起来像这样?

enter image description here

1 个答案:

答案 0 :(得分:2)

如果你需要那个,你需要设置ShiftMode如下:

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);

    } 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);
    }
}

发送你的Buttom NavigationView:

        BottomNavigationView bottomNavigationView = (BottomNavigationView) findViewById(R.id.navigation);
        disableShiftMode(bottomNavigationView);

这就是谢谢你。