Home > Enterprise >  BottomNavigationBar, doesnt showIcons when adding the menu
BottomNavigationBar, doesnt showIcons when adding the menu

Time:03-06

I'm trying to implement a bottomr navigation bar for an app. I'm using the BottomNavigationView

I was following the explanation from a youtube video step by step yet when getting to that part, when adding the menu in it doesnt even display in the activity main

I have not found an answer to a similar problem anywhere else, and im hoping its something im just missing as codes are almost identical to the explanations This is my activity main

<?xml version="1.0" encoding="utf-8"?>

<androidx.coordinatorlayout.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">


<androidx.constraintlayout.widget.ConstraintLayout
    android:id="@ id/constraintLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@ id/bnv"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:background="#d6ecef"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEndtoEndof="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:labelVisibilityMode="labeled"
        app:menu="@menu/m_1"/>

    <androidx.fragment.app.FragmentContainerView
        android:id="@ id/fragment"
        android:name="androidx.navigation.fragment.NavHostFragment"
        android:layout_width="409dp"
        android:layout_height="673dp"

        app:defaultNavHost="true"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintEndtoEndof="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:navGraph="@navigation/my_nav"
        tools:ignore="MissingConstraints" />
</androidx.constraintlayout.widget.ConstraintLayout>



</androidx.coordinatorlayout.widget.CoordinatorLayout>

This is linked from my menu class, which have ids linked to my fragments in a nav graph

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:id="@ id/firstFragment"
        android:icon="@drawable/ic_baseline_home_24"
        android:title="Home"></item>
    <item
        android:id="@ id/secondFragment"
        android:icon="@drawable/ic_baseline_directions_bus_24"
        android:title="Bus"></item>
    <item
        android:id="@ id/frag3"
        android:icon="@drawable/ic_baseline_settings_24"
        android:title="Settings"></item>

</menu>

CodePudding user response:

I struggled with your code for about half an hour. The main problem is choosing a theme. Change the theme to "Theme.AppCompat.Light.NoActionBar" The problem is solved

  • Related