BottomNavigationView不显示菜单选项

时间:2018-03-10 18:03:19

标签: android material-design android-animation bottomnavigationview

我的BottonNavigationView不显示所选项目之外的其他选项。我确实尝试设置文本颜色,但已更改的颜色是所选项目。

enter image description here

    <android.support.design.widget.BottomNavigationView
    app:menu="@menu/menu_bottom"
    android:id="@+id/bottomNavigationView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/darker_gray"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent" />

1 个答案:

答案 0 :(得分:0)

您应该可以使用以下参数设置颜色:

app:itemBackground
app:itemIconTint
app:itemTextColor

以下是我使用的完整代码:

<android.support.design.widget.BottomNavigationView
    android:id="@+id/bottom_navigation"
    android:layout_width="match_parent"
    android:layout_height="@dimen/bottom_navigation_height"
    app:itemBackground="@color/white"
    app:itemIconTint="@color/bottom_bar_item_selector"
    app:itemTextColor="@color/bottom_bar_item_selector"
    app:menu="@menu/bottom_navigation_main" />

@颜色/ bottom_bar_item_selector.xml:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_checked="true" android:color="@color/colorPrimary" />
    <item android:color="@color/grey" />
</selector>

@菜单/ bottom_navigation_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <item
        android:id="@+id/bottom_bar_item_item1"
        android:icon="@drawable/ic_1"
        android:title="@string/unions"
        app:showAsAction="ifRoom"
        android:enabled="true" />
    <item
        android:id="@+id/bottom_bar_item_item2"
        android:icon="@drawable/ic_2"
        android:title="@string/news"
        app:showAsAction="ifRoom"
        android:enabled="true" />
    <item
        android:id="@+id/bottom_bar_item_item3"
        android:icon="@drawable/ic_3"
        android:title="@string/dictionary"
        app:showAsAction="ifRoom"
        android:enabled="true" />
    <item
        android:id="@+id/bottom_bar_item_item4"
        android:icon="@drawable/ic_4"
        android:title="@string/laws"
        app:showAsAction="ifRoom"
        android:enabled="true" />
    <item
        android:id="@+id/bottom_bar_item_item5"
        android:icon="@drawable/ic_5"
        android:title="@string/for_members"
        app:showAsAction="ifRoom"
        android:enabled="true" />
</menu>