按照教程做,但是写到底部导航栏bottomNav时,使用android:layout_height="wrap_content"显示出来没有宽度,(教程视频里有默认宽度),之后在menu文件夹下写好menu.xml,使用 app:menu="@menu/menu",没有任何作用。
使用依赖包:implementation 'com.android.support:design:28.0.0'
menu.xml中的代码: (title随便写的)
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/rankinglist"
android:title="@string/hello_world"
android:icon="@drawable/ic_favorite_outline_grey600_24dp"
/>
<item
android:id="@+id/search"
android:title="@string/hello_world"
android:icon="@drawable/ic_search_grey600_24dp"
/>
<item
android:id="@+id/home"
android:title="@string/app_name"
android:icon="@drawable/ic_notifications_none_grey600_24dp"/>
</menu>
bottomBar代码:
<?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:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/yellow"
>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/fragmentContainer"
/>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/bottmNav"
android:layout_alignParentBottom="true"
app:menu="@menu/menu"
android:background="#fff"/>
</RelativeLayout>
当android:layout_height="wrap_content"时
希望知道怎么才能让这个底部导航栏成功
你可以看看这个https://llw-study.blog.csdn.net/article/details/110876383