AK105
AK105

Reputation: 53

My bottom navigation bar is not showing up any icons or text

I tried creating a bottom navigation bar on android studio but none of the icons or text is showing. I have tried looking up solutions but to no avail. When putting the navigation bar to wrap_content it does not show up which is why I temporarily set it to be 45dp. Any help would be nice!

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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">

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/bottom_nav"
        android:layout_width="match_parent"
        android:layout_height="45dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:menu="@menu/menu"
        android:background="#5D03FF"
        app:itemIconTint="#ffff"
        app:labelVisibilityMode="labeled"
        app:itemTextColor="#ffff"/>
    <FrameLayout
        android:id="@+id/fragment_container"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="@+id/bottom_nav"/>

</androidx.constraintlayout.widget.ConstraintLayout>

menu.xml

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:id="@+id/ic_qr"
        android:icon="@drawable/ic_qr"
        android:title="Scan"/>
    <item
        android:id="@+id/ic_file"
        android:icon="@drawable/ic_file"
        android:title="File"/>
    <item
        android:id="@+id/ic_generate"
        android:icon="@drawable/ic_generate"
        android:title="Create"/>
</menu>

Upvotes: 1

Views: 7075

Answers (1)

Sandesh Khutal
Sandesh Khutal

Reputation: 1809

Try this - Please find reference document for the BottomNavigationView- Link

  <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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/fragment_container"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:layout_constraintBottom_toTopOf="@+id/bottom_nav"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/bottom_nav"
        android:layout_width="match_parent"
        android:layout_height="56dp"
        android:background="#5D03FF"
        app:itemIconTint="#ffff"
        app:itemTextColor="#ffff"
        app:labelVisibilityMode="labeled"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:menu="@menu/menu" />
</androidx.constraintlayout.widget.ConstraintLayout>

Upvotes: 1

Related Questions