【发布时间】:2019-08-28 03:16:21
【问题描述】:
在我的应用程序中,我想使用BottomNavigationView 视图来显示一些片段。我有4 个fragments,我将这个fragments 设置为BottomNavigationView。
我写了下面的代码,但在大型设备屏幕(例如表格)中,我在BottomNavigationView 的中心显示了这些项目。
如下图:
但我想显示此项目填写BottomNavigationView,如下图:
我的 XML 代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="@+id/container"
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">
<fragment
android:id="@+id/mainNavigationFragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true"
android:layout_above="@+id/bottomNavigationView"
app:navGraph="@navigation/navigation_graph"/>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottomNavigationView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/windowBackground"
android:layout_alignParentBottom="true"
app:menu="@menu/navigation"/>
</RelativeLayout>
如何更改我的显示项目代码,例如图片二?
【问题讨论】:
-
你好,我想这是你的答案 :) how you fill your bottom navigation menus ?
标签: java android xml fragment bottomnavigationview