【问题标题】:Android Studio How do I get my Bottom navigation view to show my menuAndroid Studio 如何让我的底部导航视图显示我的菜单
【发布时间】:2021-02-11 02:33:45
【问题描述】:

我试图让我的材料底部导航栏显示,但每当我将“app:menu="@menu/nav_menu"”添加到我的 acitivty_main.xml 时,导航栏就会消失。我该如何解决这个问题?

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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">

    <FrameLayout
        android:id="@+id/fl_wrapper"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/bottom_navigation"/>

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/bottom_navigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        app:menu="@menu/nav_menu"
        />

</RelativeLayout>

nav_menu.xml

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">

    <item
        android:id="@+id/navigation_profile"
        android:icon="@drawable/ic_profile"
        android:title="Favorites"
        android:visible="true"/>

    <item
        android:id="@+id/navigation_steps"
        android:icon="@drawable/ic_steps"
        android:title="Steps"
        android:visible="true"
        />

    <item
        android:id="@+id/navigation_home"
        android:icon="@drawable/ic_action_home"
        android:title="Home"
        android:visible="true"/>
</menu>

我不确定为什么它不起作用。当我拿走 app:menu 部分时,它会显示一个黑色的导航栏,但一旦我添加菜单,导航栏就会消失。

【问题讨论】:

    标签: android xml android-studio


    【解决方案1】:

    我认为您需要将背景颜色设置为底部导航菜单。 尝试添加 android:background="?android:attr/windowBackgroud" 在底部导航菜单中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-28
      • 2018-09-07
      • 2020-04-29
      • 2021-06-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多