即使没有填充整个空间,底部导航栏标签也会被剪切到下一行

7 android-jetpack-compose

如何在单行中制作图标标签而不破坏它,减小字体大小有帮助,但变小会难以阅读。

底部导航实现:

    BottomNavigation(backgroundColor = Color.White) {
        items.forEach { item ->
            BottomNavigationItem(
                selected = currentRoute == item.route,
                onClick = { /*TODO*/ },
                icon = {
                    if (currentRoute == item.route) ActiveIcon(item.activeIcon)
                    else Icon(painterResource(item.disableIcon), null)
                },
                label = {
                    Text(
                        stringResource(item.title), // Label
                        fontWeight = FontWeight.SemiBold
                    )
                },
            )
        }
    }
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

And*_*Dev 9

在您的文本上使用softWrap并将其设置为 false:

BottomNavigation(backgroundColor = Color.White) {
  items.forEach { item ->
        BottomNavigationItem(
             selected = currentRoute == item.route,
             onClick = { /*TODO*/ },
             icon = {
                  if (currentRoute == item.route) ActiveIcon(item.activeIcon)
                  else Icon(painterResource(item.disableIcon), null)
             },
             label = {
                  Text(
                        stringResource(item.title), // Label
                        fontWeight = FontWeight.SemiBold,
                        softWrap = false
                  )
             },
        )
   }
}
Run Code Online (Sandbox Code Playgroud)

注意:BottomNavigation 不可滚动,因此如果导航栏中的项目数量太多,文本将在超出选项卡宽度的项目上被剪裁。这是设计使然。