Android 如何强制BottomNavigationView标签为多行

Android 如何强制BottomNavigationView标签为多行,android,bottomnavigationview,material-components,material-components-android,android-bottomnav,Android,Bottomnavigationview,Material Components,Material Components Android,Android Bottomnav,我有一个带有长标签文本的BottomNavigationView,它没有显示完整的标签 我发现BottomNavigationView上的标签有一个maxLines=“1”,但我不知道如何修改它以允许使用两行标签 目前没有办法更改底部导航菜单视图中的项目使用的android:maxLines=“1” 这是一种变通方法,它可以停止工作,以便在将来的版本中使用 BottomNavigationMenuView menuView = (BottomNavigationMenuView) bottomN

我有一个带有长标签文本的
BottomNavigationView
,它没有显示完整的标签


我发现
BottomNavigationView
上的标签有一个
maxLines=“1”
,但我不知道如何修改它以允许使用两行标签

目前没有办法更改
底部导航菜单视图中的项目使用的
android:maxLines=“1”

这是一种变通方法,它可以停止工作,以便在将来的版本中使用

BottomNavigationMenuView menuView = (BottomNavigationMenuView) bottomNavigationView.getChildAt(0);

for (int i = 0; i < menuView.getChildCount(); i++) {
      BottomNavigationItemView item = (BottomNavigationItemView) menuView.getChildAt(i);
      TextView smallLabel = item.findViewById(R.id.smallLabel);
      TextView largeLabel = item.findViewById(R.id.largeLabel);

      smallLabel.setMaxLines(2);
      largeLabel.setMaxLines(2);
}

您还可以在项目中添加自己的
design\u bottom\u navigation\u item.xml
。由于名称完全相同,它将覆盖设计库中的名称。只需确保ID和视图类型相同


请注意,如果他们在以后版本的库中更改了原始文件的文件名,则修复程序将不再有效。

发布您的代码!我没有对常规导航代码做任何更改。因为我不知道要改变什么。
<merge xmlns:android="http://schemas.android.com/apk/res/android">
  <ImageView
      android:id="@+id/icon"
      ../>
  <com.google.android.material.internal.BaselineLayout
    ..>
    <TextView
        android:id="@+id/smallLabel"
        android:maxLines="1" 
        ../>
    <TextView
        android:id="@+id/largeLabel"
        android:maxLines="1"
        .../>
  </com.google.android.material.internal.BaselineLayout>
</merge>