为什么BottomNavigationView不显示我的菜单?Android Studio ,Kotlin

c0vxltue  于 2023-05-21  发布在  Android
关注(0)|答案(1)|浏览(215)

BottomNavigationView没有显示我的菜单,不知道该怎么办,我试过删除gradle中的依赖项,但它不起作用,我只是在学习android studio如何工作,所以也许我忘记了一些愚蠢的事情,请帮助我
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>

这是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>

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'
}
zte4gxcn

zte4gxcn1#

只需使用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>

相关问题