我想知道是否有一种方法可以使底部导航栏图标标题像 marquee 一样滚动。我已经看到过类似的应用程序,并试图找到一些方法,但找不到任何方法。因此,如果有人可以帮助我,我将不胜感激。
答案 0 :(得分:0)
有最简单的解决方案。适用于材料组件版本1.0.0-1.2.0-alpha02。
fun BottomNavigationView.findAllLabels(): Sequence<TextView> {
return sequence {
children.forEach { bottomNavigationChild ->
if (bottomNavigationChild is ViewGroup) {
bottomNavigationChild.children.forEach {
val smallLabel = it.findViewById<TextView>(
com.google.android.material.R.id.smallLabel
)
yield(smallLabel)
val largeLabel = it.findViewById<TextView>(
com.google.android.material.R.id.largeLabel
)
yield(largeLabel)
}
}
}
}
}
// Your BottomNavigationView
bottomNavigationView.findAllLabels().forEach {
it.apply {
ellipsize = TextUtils.TruncateAt.MARQUEE
setSingleLine(true)
// For infinite loop, comment if it's not required
marqueeRepeatLimit = -1
}
}