Android底部导航查看项目文本颜色?

时间:2017-04-19 09:32:55

标签: android android-support-library android-menu android-bottom-nav-view

我开始使用Android底部导航视图。但我面临一个问题。如果我向底部导航视图添加了5个项目,则只显示项目文本的选定项目。如果我添加3项,它工作正常。请告诉我如何显示所有5个项目的项目文本。 提前谢谢。

menu.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>

依赖性:   编译&#39; com.android.support:appcompat-v7:25.0.1&#39;     编译&#39; com.android.support:design:25.0.0&#39;

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

1 个答案:

答案 0 :(得分: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);
        }
    }

更新:

您可以更改此How to change the Menu text size

之类的菜单文字大小