代码之家  ›  专栏  ›  技术社区  ›  Paul Alexander

底部导航栏不显示图标或文本

  •  0
  • Paul Alexander  · 技术社区  · 7 年前

    在我的Android应用程序中,尝试实现带有图标和文本的底部导航栏有点麻烦。
    该条当前按预期运行,并将您带到所需的片段,但由于某些原因没有显示图标或文本。

    我已经做了一些搜索,但还没有找到一个解决方案或原因,为什么它是这样的行为。
    任何帮助都将不胜感激。谢谢。

    活动\主.xml

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.design.widget.CoordinatorLayout 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"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity">
    
        <FrameLayout
            android:id="@+id/frame_container"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" />
    
        <android.support.design.widget.BottomNavigationView
            android:id="@+id/navigation"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:background="?android:attr/windowBackground"
            app:itemBackground="@color/turquoise"
            android:foreground="@color/colorPrimary"
            app:itemIconTint="@android:color/white"
            app:itemTextColor="@android:color/white"
            app:menu="@menu/navigation" />
    
    </android.support.design.widget.CoordinatorLayout>
    

    导航.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/nav_0"
            android:icon="@drawable/ic_launcher_foreground"
            android:title="home"
            app:showAsAction="ifRoom|withText"/>
    
        <item
            android:id="@+id/nav_1"
            android:icon="@drawable/ic_launcher_foreground"
            android:title="email"
            app:showAsAction="ifRoom|withText"/>
    
        <item
            android:id="@+id/nav_2"
            android:icon="@drawable/ic_home"
            android:title="profile"
            app:showAsAction="ifRoom|withText"/>
    
        <item
            android:id="@+id/nav_3"
            android:icon="@drawable/ic_home"
            android:title="map"
            app:showAsAction="ifRoom|withText"/>
    
    </menu>
    

    在MainActivity.java中

     toolbar = getSupportActionBar();
    
            BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation);
            navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
    
    1 回复  |  直到 7 年前
        1
  •  1
  •   Peyman    7 年前

    删除 android:foreground="@color/colorPrimary" 你的内在属性 BottomNavigationView