删除 BottomNavigationView 图标和中心标题

Joe*_*Joe 5 java xml android android-layout android-fragments

我有一个包含 3 个项目的底部导航视图。我只想为每个选项卡提供居中文本,因此希望完全删除图标(不仅使它们透明)。

如何删除图标并使标题居中?

这就是我所拥有的: 在此输入图像描述 这就是我要的: 在此输入图像描述

我的代码:(更喜欢 XML 中的解决方案)

<merge  xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="55dp"
        android:layout_alignParentBottom="true">

        <com.google.android.material.bottomnavigation.BottomNavigationView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/navigationBar"
            android:background="@color/navigation"
            app:theme="@style/BottomNavigationTheme"
            app:menu="@menu/bottom_navigation_menu"
            android:minHeight="@dimen/abc_action_bar_default_height_material">

        </com.google.android.material.bottomnavigation.BottomNavigationView>

    </RelativeLayout>

</merge>
Run Code Online (Sandbox Code Playgroud)

底部导航菜单.xml

<?xml version="1.0" encoding="utf-8"?>
<menu   xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto">

    <item
        android:id="@+id/ic_home"
        android:title="@string/home">
    </item>

    <item
        android:id="@+id/ic_today"
        android:title="@string/today">
    </item>

    <item
        android:id="@+id/ic_you"
        android:title="@string/you">
    </item>

</menu>
Run Code Online (Sandbox Code Playgroud)

小智 -1

您可以使用底部导航视图的此属性来隐藏文本,它会自动将您的图标居中,我认为您不要使用 minHeight 属性,先生。 app:labelVisibilityMode="unlabeled"