首页 > 解决方案 > BottomNavigationView:更改标题和图标之间的间隙大小

问题描述

我想改变BottomNavigationView高度,改变尺寸后项目位置不会改变。

这更像是中间间隙不会自动改变。但是,我想更改此间隙大小。

这是Before更改高度和项目大小。这些间隙大小适用于这些项目,但缩小项目会导致 UI 问题。 在此处输入图像描述

而这些是After 在此处输入图像描述

这是我的代码:

<com.google.android.material.bottomnavigation.BottomNavigationView
    android:id="@+id/nav_view"
    style="@style/MyBottomNavigationView"
    android:layout_width="0dp"
    android:layout_height="?android:listPreferredItemHeightSmall"
    android:background="?android:attr/windowBackground"
    app:itemIconSize="20dp"
    app:labelVisibilityMode="labeled"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:menu="@menu/bottom_nav_menu" />

<com.google.android.material.bottomnavigation.BottomNavigationView ...如果你们知道更好的图书馆,我也在使用,请建议我。

标签: androidxmlbottomnavigationview

解决方案


BottomNavigationView通过覆盖以下尺寸来更改高度

<dimen name="design_bottom_navigation_height" tools:override="true">40dp</dimen>

这将增加/减少图标和文本之间的间隙大小。

参考:material-components-android


推荐阅读