Я использовал BottomNavigationView в своем файле activity_main.xml, сначала я поместил только 1 элемент в свое меню, но затем я добавил еще один элемент в свое меню, но он показывает только элемент, добавленный в начале, даже если я удаляювсе в моем меню, оно все еще показывает только элемент, который я вставил в свое меню в начале. Как я могу это исправить?
Я пытался перестроить весь файл activity_main.xml и menu.xml, но он все еще не исправлен. Ниже приведены мои activity_main.xml и menu.xml
menu.xml:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/home"
android:title="@string/Home"
android:icon="@drawable/home" />
<item android:id="@+id/profile"
android:title="@string/Profile"
android:icon="@drawable/profile" />
</menu>
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/bottomNavigationView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/yellow"
app:itemIconTint="@color/black"
app:itemTextColor="@color/black"
app:labelVisibilityMode="auto"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:menu="@menu/menu" />
</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:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'com.android.support:support-core-utils:27.1.1'
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support:recyclerview-v7:29.0.0'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
В начале я добавляю только элемент: Домой , позже я добавляю свой второй элемент: Профиль , но в навигационном представлении отображается только Дом, который я добавил при созданииit.
Эта проблема была исправлена после того, как я удалил строку ниже из gradle, и я не знаю, почему эта строка находится в моем gradle.
sourceSets { main { res.srcDirs = ['src/main/res', 'src/main/res/menu'] } }