图标没有出现在BottomNavigationBar中

时间:2017-12-18 18:13:31

标签: android icons bottomnavigationview

This links contains the screenshot. It shows the dark places inplace of the icons. The shape of those places is just like that of the icons but icons are not appearing.

MainActivity.java     [private BottomNavigationView.OnNavigationItemSelectedListener     mOnNavigationItemSelectedListener             = new BottomNavigationView.OnNavigationItemSelectedListener(){

    @Override
    public boolean onNavigationItemSelected(@NonNull MenuItem item) {

        switch (item.getItemId()) {
            case R.id.navigation_buy:
                fragment = new Buy();
                break;
            case R.id.navigation_orders:
                fragment = new Orders();
                break;
            case R.id.navigation_navigation:
                fragment = new Navigation();
                break;
            case R.id.navigation_chat:
                fragment = new Chat();
                break;
            case R.id.navigation_invite:
                fragment = new Invite();
                break;

        }
        final FragmentTransaction transaction = 
fragmentManager.beginTransaction();
        transaction.replace(R.id.content, fragment).commit();
        return true;

    }

};]

menu.xml
[<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<item
    android:id="@+id/navigation_buy"
    android:icon="@drawable/buy_ic"
    android:title="@string/title_buy"
    app:showAsAction="ifRoom"/>

<item
    android:id="@+id/navigation_orders"
    android:icon="@drawable/orders_ic"
    android:title="@string/title_orders"
    app:showAsAction="ifRoom"/>

<item
    android:id="@+id/navigation_navigation"
    android:icon="@drawable/navigation_ic"
    android:title="@string/title_navigation"
    app:showAsAction="ifRoom"/>
<item
    android:id="@+id/navigation_chat"
    android:icon="@drawable/chat_ic"
    android:title="@string/title_chat"
    app:showAsAction="ifRoom"/>
<item
    android:id="@+id/navigation_invite"
    android:icon="@drawable/invite_ic"
    android:title="@string/title_invite"
    app:showAsAction="ifRoom"/>

</menu>]

activity_main.xml
<android.support.design.widget.BottomNavigationView
    android:id="@+id/navigation"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    app:itemBackground="@color/colorPrimary"
    app:itemTextColor="@color/white"
    app:menu="@menu/navigation" />

1 个答案:

答案 0 :(得分:1)

使用itemIconTint代替app:itemBackground="@color/colorPrimary"

app:itemIconTint="@color/colorPrimary"