'Why does my bottom navigation view only contain the text of the first item?
I want my navigation bar to include the icon and text of all items, however I am only getting the text and icon for the first item (the rest only display the icon).
It seems it is dependent on the order, as I have switched the order of the items and only the first item displays both logo and icon. This means that there is no syntax error in the rest of the items as they are all behaving the same way.
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:itemBackground="@color/colorPrimary"
app:itemIconTint="@android:color/white"
app:itemTextColor="@android:color/white"
app:layout_constraintBottom_toBottomOf="@+id/linear"
android:layout_gravity="start"
app:layout_constraintRight_toRightOf="@+id/linear"
app:menu="@menu/bottom_nav_menu" />
<?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/Home"
android:enabled="true"
android:icon="@drawable/baseline_home_white_18dp"
android:title="@string/home"
app:showAsAction="ifRoom|withText"
/>
<item
android:id="@+id/Social"
android:enabled="true"
android:icon="@drawable/baseline_public_white_18dp"
android:title="Social"
app:showAsAction="ifRoom|withText" />
<item
android:id="@+id/Diagnoses"
android:enabled="true"
android:icon="@drawable/baseline_image_search_white_18dp"
android:title="@string/diagnoses"
app:showAsAction="ifRoom|withText" />
<item
android:id="@+id/Inbox"
android:title="Artists"
android:enabled="true"
android:icon="@drawable/baseline_inbox_white_18dp"
app:showAsAction="ifRoom|withText" />
<item
android:id="@+id/rewards"
android:enabled="true"
android:icon="@drawable/baseline_store_mall_directory_white_18dp"
android:title="@string/rewards"
app:showAsAction="ifRoom|withText" />
</menu>
I expect the text and icon to be on every item, however the text is only showing on the first item (doesn't matter which item is placed first).
Solution 1:[1]
When setting e.g.itemTextColor
you should use a selector instead of a color to support the checked state.
res/color/selector_bottom_navigation.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#fff" android:state_checked="false" />
<item android:color="#000" />
</selector>
Solution 2:[2]
Add this method to your BottomNavigationView:
app:labelVisibilityMode="labeled"
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | Wild Teddy |