android - 中心底部导航栏图标

标签 android bottomnavigationview android-support-design

我试图让 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 是这样的:

Bottom navigation bar

我正在使用实现“com.android.support:design:27.0.1”

编辑:

正如您在布局检查器中看到的那样,图标大小相同,均为 63x63 像素,但选中图标的 Y 轴小了 5 像素。

Layout Inspector

最佳答案

从设计支持库 28.0.0-alpha1 开始,您可以使用该属性

app:labelVisibilityMode="未标记"

关于android - 中心底部导航栏图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51611638/

相关文章:

android - AlarmManager Android 每天上午10点触发闹钟

安卓 : Add rounded corners to BottomAppBar with circular anchored FAB

android - 如何根据谷歌新指南实现底部导航选项卡

android - 如何禁用某些 fragment 的底部导航

android - Resources$NotFoundException : If the resource you are trying to use is a vector resource, 您可能以不受支持的方式引用它

android - CollapsingToolbarLayout 标题在与侧抽屉重叠时消失

android - float 操作按钮不会停留在 SnackBar 之上

android - 如何使用 Kotlin 在 Android Studio 中的 RecyclerView 上添加 Onclick 监听器?

android - 在手机上构建游戏。原生还是引擎?

android - 在 android 中设置 ImageView 资源时出错