BottomNavigationView 图标上方显示的导航项目文本

ten*_*dai 6 android bottomnavigationview

升级依赖后:

'com.google.android.material:material:xxx'

1.4.01.5.0,导航项文本以某种方式从锚定在图标下方更改为图标上方:

从:

在此输入图像描述

到:

在此输入图像描述

这是一个功能还是一个错误,有修复吗?

小智 14

从 1.4.0 更新到 1.5.0 后,我遇到了同样的问题,但就我而言,问题是因为我使用继承自的 BottomNavigationView 主题而引起的Widget.Design.BottomNavigationView

<com.google.android.material.bottomnavigation.BottomNavigationView
    android:id="@+id/bnv"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?android:attr/windowBackground"
    android:theme="@style/Widget.BottomNavigationView"
    ...
/>
Run Code Online (Sandbox Code Playgroud)

查看Widget.Design.BottomNavigationViewxml 后,我意识到在 1.5.0 版本中minHeight添加了一个属性,导致影响我们的问题。

所以我添加<item name="android:minHeight">0dp</item>了这样的自定义样式:

<style name="Widget.BottomNavigationView" parent="Widget.Design.BottomNavigationView">
    ...
    <item name="android:minHeight">0dp</item>
</style>
Run Code Online (Sandbox Code Playgroud)

问题解决了!


azi*_*ian 5

阅读1.5.0的发行说明可以看到Material3主题介绍。我仔细检查了BottomNavigation.md然后我发现了:事实证明需要使用新Material3主题而不是MaterialComponent

<style name="Theme.Inventory" parent="Theme.Material3.Light.NoActionBar">
    ...
    <item name="bottomNavigationStyle">@style/Widget.App.BottomNavigationView</item>
</style>

<style name="Widget.App.BottomNavigationView" parent="Widget.Material3.BottomNavigationView">
    <item name="materialThemeOverlay">@style/ThemeOverlay.App.BottomNavigationView</item>
</style>

<style name="ThemeOverlay.App.BottomNavigationView" parent="">
    <item name="colorSurface">@color/shrine_blue_100</item>
    <item name="colorOnSurfaceVariant">@color/shrine_blue_900</item>
</style>
Run Code Online (Sandbox Code Playgroud)

另外,我android:theme="@style/MyBottomNavigationView"BottomNavigationViewin 中删除了xml