![](/img/trans.png)
[英]Android Menu Doesn't Appear Under Android Studio's “Tools” Menu. How to bring it up?
[英]Why doesn't the Bottom Navigation Menu appear in Android Studio
我正在嘗試為我嘗試制作的應用程序添加底部導航菜單,我按照視頻的每一步操作,但底部導航菜單仍然沒有顯示。 有人能幫我嗎?
儀表盤 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="Dashboard.Dashboard">
<androidx.fragment.app.FragmentContainerView
android:id="@+id/fragmentContainerView"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="0dp"
app:defaultNavHost="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:navGraph="@navigation/bottom_nav" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_nav_view"
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_menu"/>
</androidx.constraintlayout.widget.ConstraintLayout>
Bottom_Nav_Menu xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/feedFragment"
android:title="@string/home"
android:icon="@drawable/home_icon"/>
<item
android:id="@+id/searchFragment"
android:title="@string/search"
android:icon="@drawable/search_icon"/>
<item
android:id="@+id/postFragment"
android:title="@string/add"
android:icon="@drawable/add_post"/>
<item
android:id="@+id/notificationFragment"
android:title="@string/notification"
android:icon="@drawable/notification_icon"/>
<item
android:id="@+id/profileFragment"
android:title="@string/profile"
android:icon="@drawable/person_icon"/>
</menu>
沒關系,我以某種方式讓它工作。 一切都運行良好。 在使用底部導航欄之前,我只需要添加一個庫。
這個庫在你的 build.grandle
implementation 'androidx.navigation:navigation-fragment:2.4.1'
implementation 'androidx.navigation:navigation-ui:2.4.1'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.