AndroidX BottomNavigationView

当前,我正在设计一个Android应用程序,并且BottomNavigationView有一项活动。我有一些问题。尽管我指示res文件夹中的菜单文件,但它没有显示任何内容。看来我的导航栏的高度仍然等于0dp。 这是我在res / menu目录中的菜单文件:

 <?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:id="@+id/nav_home"
        android:icon="@drawable/ic_home_icon"
        android:title="@string/nav_home"/>
    <item
        android:id="@+id/nav_notification"
        android:icon="@drawable/ic_notification_icon"
        android:title="@string/nav_notification"/>
    <item
        android:id="@+id/nav_schedule"
        android:icon="@drawable/ic_schedule_icon"
        android:title="@string/nav_schedule"/>
    <item
        android:id="@+id/nav_profile"
        android:icon="@drawable/ic_profile_icon"
        android:title="@string/nav_profile"/>
</menu>

这是我的活动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=".Homeactivity">

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:menu="@menu/bottom_nav"/>

</androidx.constraintlayout.widget.ConstraintLayout>

依赖项,应用程序模块:

implementation fileTree(dir: 'libs',include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'com.google.android.material:material:1.0.0'
lakewent20091231 回答:AndroidX BottomNavigationView

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3170050.html

大家都在问