【问题标题】:Centrally place menu items in bottom navigation view without text在没有文本的底部导航视图中集中放置菜单项
【发布时间】: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>

这是底部导航的 ss,我需要在底部导航菜单的中心放置图标。

【问题讨论】:

    标签: android xml menu material-design bottomnavigationview


    【解决方案1】:

    去掉 xml 文件中的android:title="",它应该可以工作

    【讨论】:

    • 你可以分享更新后的代码并添加新标签吗?
    • 我想在底部导航视图或约束布局中添加重力?
    • 约束布局
    • 摆脱android:title,这可能对我有帮助
    • 我试过了,但不允许。顺便说一句,我已经解决了这个问题:)
    【解决方案2】:

    所以我通过更改解决了这个问题

    app:labelVisibilityMode="labeled"
    

    app:labelVisibilityMode="unlabeled"
    

    因为我没有在菜单中使用任何标题。

    【讨论】:

    • 哦,是的,我错过了! gg!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-07-28
    • 1970-01-01
    • 1970-01-01
    • 2020-04-29
    • 1970-01-01
    • 2020-04-08
    • 1970-01-01
    相关资源
    最近更新 更多