实现 5 项 BottomNavigationView - 始终显示标签 - 我使用以下方法:
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="?android:attr/windowBackground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="@menu/navigation"
app:labelVisibilityMode="labeled"/>
不幸的是,结果在活动时用连字符连接单词,如图所示:
我尝试为标签的活动文本设置不同的样式:
app:itemTextAppearanceActive="@style/text_navigation_active_labels"
-- 样式.xml --
<style name="text_navigation_active_labels">
<item name="android:breakStrategy">simple</item>
<item name="android:hyphenationFrequency">none</item>
</style>
但结果是完全相同的(无论我只使用中断策略、连字频率还是两者都使用)。我目前正在 API 27 物理手机上测试它。
任何帮助表示赞赏。
由于 5 个项目可能会占用大量空间,因此有必要牺牲文本大小。为了解决这个问题,向 BottomNavigationView 文本添加自定义样式即可完成工作:
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
...
app:itemTextAppearanceActive="@style/navTextActive"
app:itemTextAppearanceInactive="@style/navTextInactive"/>
在 styles.xml 上:
<style name="navTextInactive">
<item name="android:textSize">11sp</item>
</style>
<style name="navTextActive">
<item name="android:textSize">12sp</item>
</style>
Result:
固定导航栏 https://i.stack.imgur.com/ThA3o.png
希望它可以帮助任何人!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)