有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Android在底部导航栏中禁用缩放效果

我试图实现底部导航栏。在这里,我面临一个问题,当菜单项在点击时进入缩放,这导致一些标题文本从栏截断

就像截图一样 enter image description hereenter image description here

是否有任何解决方案可以防止这种缩放效果


共 (4) 个答案

  1. # 1 楼答案

    public static class BottomNavigationViewHelper {
        @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.setShifting(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);
            }
        }
    }
    @Override
    protected void onStop() {
        super.onStop();
    }
    

    }

    在这之后把这个

        BottomNavigationViewHelper.disableShiftMode(bottomNavigationView);
    

    我试过这个,效果很好

  2. # 2 楼答案

    我做了很多尝试和错误,现在我意识到更好的选择是使用第三方库作为底部栏。更好的解决方案之一是roughike有很多定制可用

  3. # 3 楼答案

    你所要做的就是在你的尺寸表中覆盖设计\底部\导航\活动\文本\大小的尺寸。xml文件

    <dimen name="design_bottom_navigation_active_text_size" tools:override = "true" >12sp</dimen>
    

    这里12sp是非活动底部导航项的默认文本大小。对活动的底部导航项也设置相同的设置。您将没有缩放效果

  4. # 4 楼答案

    Text labels provide short, meaningfully definitions to bottom navigation icons. Avoid long text labels as these labels do not truncate or wrap.

    根据指南,你不应该使用长文本

    enter image description here

    Source