skip to Main Content

BottomNavigationView is not showing my menu, have no idea what to do, I’ve tried deleting dependencies in gradle, but its not working, I’m only learning how android studio works, so maybe I forgot something stupid , please help me

how it looks like

content_main:

<?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:id="@+id/ConstraintLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:layout_width="0dp"
        android:layout_height="60dp"
        android:layout_gravity="bottom"
        android:background="#297385"
        android:visibility="visible"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:menu="@menu/bottom_menu"
        tools:visibility="visible" />
</androidx.constraintlayout.widget.ConstraintLayout>

this is bottom_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/settings"
        android:title="@string/settings"
        android:icon="@drawable/settings"
        app:showAsAction="ifRoom"
        android:visible="true"
        />
    <item
        android:id="@+id/notes"
        android:visible="true"
        android:title="@string/notes"
        android:icon="@drawable/note"
        app:showAsAction="ifRoom"
        />
    <item
        android:id="@+id/shop_list"
        android:visible="true"
        android:title="@string/shop_list"
        android:icon="@drawable/list"
        app:showAsAction="ifRoom"
        />
    <item
        android:id="@+id/new_item"
        android:visible="true"
        android:title="@string/new_item"
        android:icon="@drawable/ic_new"
        app:showAsAction="ifRoom"
        />
</menu>

dependencies in gradle:

dependencies {

    implementation 'androidx.core:core-ktx:1.10.1'
    //
    implementation 'androidx.room:room-ktx:2.5.1'
    kapt "androidx.room:room-compiler:2.5.1"
    implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.6.1'
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.1'
    implementation 'androidx.preference:preference-ktx:1.2.0'
    implementation(platform("org.jetbrains.kotlin:kotlin-bom:1.8.0"))
    //
    implementation 'com.google.android.material:material:1.9.0'
    implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.6.1'
    implementation 'androidx.activity:activity-compose:1.7.1'
    implementation platform('androidx.compose:compose-bom:2022.10.00')
    implementation 'androidx.compose.ui:ui'
    implementation 'androidx.compose.ui:ui-graphics'
    implementation 'androidx.compose.ui:ui-tooling-preview'
    implementation 'androidx.compose.material3:material3'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.5'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
    androidTestImplementation platform('androidx.compose:compose-bom:2022.10.00')
    androidTestImplementation 'androidx.compose.ui:ui-test-junit4'
    debugImplementation 'androidx.compose.ui:ui-tooling'
    debugImplementation 'androidx.compose.ui:ui-test-manifest'
}

2

Answers


  1. Just try this with content_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"
        android:id="@+id/ConstraintLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
    
        <FrameLayout
            android:id="@+id/frameLayout"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            app:layout_constraintBottom_toTopOf="@+id/bottomNavigationView"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />
    
        <com.google.android.material.bottomnavigation.BottomNavigationView
            android:id="@+id/bottomNavigationView"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            app:backgroundTint="#297385"
            app:itemIconTint="#FFFFFF"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:menu="@menu/bottom_menu" />
    </androidx.constraintlayout.widget.ConstraintLayout>
    
    Login or Signup to reply.
  2. your problem started when instead of choosing an xml project you chose a Compose project in the templates. This is why all the dependencies and theme.xml file is different and is prepared for a compose project.
    To fix all this without recreating the project just in your theme.xml file put this:

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <style name="Theme.ShoppingList" parent="Theme.AppCompat.Light.NoActionBar" />
    </resources>
    

    and the dependencies in the build.gradle file you leave them like this:

        dependencies {
        implementation 'androidx.core:core-ktx:1.10.1'
        //
        implementation 'androidx.room:room-ktx:2.5.1'
        kapt "androidx.room:room-compiler:2.5.1"
        implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.6.1'
        implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.1'
        implementation 'androidx.preference:preference-ktx:1.2.0'
        implementation(platform("org.jetbrains.kotlin:kotlin-bom:1.8.0"))
        implementation 'androidx.appcompat:appcompat:1.6.1'
        //
        implementation 'com.google.android.material:material:1.9.0'
        implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.6.1'
        implementation 'androidx.activity:activity-compose:1.7.1'
        implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
        testImplementation 'junit:junit:4.13.2'
        androidTestImplementation 'androidx.test.ext:junit:1.1.5'
        androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
    }
    

    where are your Activity classes and the rest you will have ui.theme folders inside those folders Color.kt and Theme.kt for compose, delete these folders, are not for xml and that’s it, everything will work.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search