首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >BottomNavigationView不膨胀

BottomNavigationView不膨胀
EN

Stack Overflow用户
提问于 2021-07-01 01:52:43
回答 1查看 49关注 0票数 0

我正尝试在activity_main.xml中给BottomNavigationView充气,但无济于事。

下面是我在menu资源目录中的bottom_navigation.xml

代码语言:javascript
复制
<?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

代码语言:javascript
复制
<?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的第一个问题,所以我的问题格式可能不是最好的。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-11-09 09:47:57

参加聚会有点晚了。但那天我终于想通了。缺少前缀@+id/

代码语言:javascript
复制
    <item
        android:id="@+id/nav_library"
        android:icon="@drawable/svg_library"
        android:title="Library" />
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68199489

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档