【发布时间】:2021-10-12 12:03:27
【问题描述】:
我正在使用带有菜单的底部导航视图。我需要将菜单图标放在 BNV 的中心,因为我不想用图标放置文本。
这是我的底部导航视图:
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.fragment.app.FragmentContainerView
android:id="@+id/nav_host_fragment_dashboard"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="0dp"
app:defaultNavHost="true"
app:layout_constraintBottom_toTopOf="@+id/bottomNavigationView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:navGraph="@navigation/dashboard_navigation" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottomNavigationView"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:menu="@menu/bottom_nav_menu"
app:labelVisibilityMode="labeled"
android:background="@color/white"
app:elevation="12dp"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
这里是菜单代码
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/homeFragment"
android:title=""
android:icon="@drawable/home_icon"/>
<item
android:id="@+id/chatFragment"
android:title=""
android:icon="@drawable/chat_icon"
/>
<item
android:id="@+id/nonSulinCommunityFragment"
android:title=""
android:icon="@drawable/nonsulin_community_icon"
/>
<item
android:id="@+id/notificationsFragment"
android:title=""
android:icon="@drawable/notification_icon"
/>
<item
android:id="@+id/profileFragment"
android:title=""
android:icon="@drawable/profile_icon"
/>
</menu>
【问题讨论】:
标签: android xml menu material-design bottomnavigationview