5

我开始研究 Android 底部导航视图。但我面临一个问题。如果我在底部导航视图中添加了 5 个项目,则只有选定的项目显示项目文本。如果我添加了 3 个项目,它工作正常。任何人请告诉我如何显示所有 5 个项目的项目文本。先感谢您。

菜单.xml:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context="com.reloadapp.reload.activity.IconTabsActivity">
    <item
        android:id="@+id/action_favorites"
        android:enabled="true"
        android:icon="@drawable/home_40"
        android:title="Home"
        app:showAsAction="ifRoom" />
    <item
        android:id="@+id/action_schedules"
        android:enabled="true"
        android:icon="@drawable/profile_40"
        android:title="Profile"
        app:showAsAction="ifRoom" />
    <item
        android:id="@+id/action_music"
        android:enabled="true"
        android:icon="@drawable/reload_40"
        android:title="Reload cash"
        app:showAsAction="ifRoom" />
    <item
        android:id="@+id/action_musi"
        android:enabled="true"
        android:icon="@drawable/notifications"
        android:title="Notifications"
        app:showAsAction="ifRoom" />
    <item
        android:id="@+id/action_mus"
        android:enabled="true"
        android:icon="@drawable/menu_40"
        android:title="More"
        app:showAsAction="ifRoom" />
</menu>

依赖:编译'com.android.support:appcompat-v7:25.0.1' 编译'com.android.support:design:25.0.0'

 <android.support.design.widget.BottomNavigationView
        android:id="@+id/bottom_navigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:itemBackground="@color/textColorPrimary"
        app:menu="@menu/menu_icon_tabs"
        app:itemIconTint="@color/colorPrimary"
        app:itemTextColor="@color/colorPrimary"
        android:layout_alignParentBottom="true">
    </android.support.design.widget.BottomNavigationView>
4

1 回答 1

6

删除底部导航中的动画,使用此代码

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

方法

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

更新:

您可以像这样更改菜单文本大小如何更改菜单文本大小

于 2017-04-19T09:38:30.697 回答