我正尝试在activity_main.xml中给BottomNavigationView充气,但无济于事。
下面是我在menu资源目录中的bottom_navigation.xml:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="nav_library"
android:icon="@drawable/svg_library"
android:title="Library" />
<item
android:id="nav_search"
android:icon="@drawable/svg_search"
android:title="Search" />
<item
android:id="nav_liked"
android:icon="@drawable/svg_heart"
android:title="Liked" />
</menu>这是我的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"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/nav_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:menu="@menu/bottom_navigation"
android:background="?android:attr/windowBackground" />
</RelativeLayout>android:layout_height="wrap_content"似乎没有检测到菜单的图标和标题,因此,导航栏的高度和宽度都是0。
Here's an image with the wrap_content attribute. (嵌入没有足够的rep )
请给我建议。
附言:这是我关于Stack Overflow的第一个问题,所以我的问题格式可能不是最好的。
发布于 2021-11-09 09:47:57
参加聚会有点晚了。但那天我终于想通了。缺少前缀@+id/
<item
android:id="@+id/nav_library"
android:icon="@drawable/svg_library"
android:title="Library" />https://stackoverflow.com/questions/68199489
复制相似问题