如何设置BottomNavigationView letterSpacing?

问题描述 投票:0回答:1

在TextView中,我可以使用android:letterSpacing="0.1"来设置字母间距

但这在BottomNavigationView中不起作用

我使用此代码设置BottomNavigationView的字体样式

我想我也可以在这里设置字母间距,但我找不到相关的方法

如何设置字母间距?

<android.support.design.widget.BottomNavigationView
    android:id="@+id/navigation"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginEnd="0dp"
    android:layout_marginStart="0dp"
    app:menu="@menu/navigation" >

val font = Typeface.createFromAsset(assets, "UniversNextPro-LightCond.otf")
val typefaceSpan = CustomTypefaceSpan("", font)
navigation.menu.size()
for (i in 0 until navigation.menu.size()) {
    val menuItem = navigation.menu.getItem(i)
    val spannableTitle = SpannableStringBuilder(menuItem.getTitle())
    spannableTitle.setSpan(typefaceSpan, 0, spannableTitle.length, 0)
    menuItem.setTitle(spannableTitle)
}
android kotlin bottomnavigationview
1个回答
2
投票

我能够这样做:

  1. 创建父级为Widget.Design.BottomNavigationView的样式
<style name="BottomNavigationTheme" parent="Widget.Design.BottomNavigationView">
    <item name="android:letterSpacing">0.1</item>
</style>
  1. 将样式设置为底部导航视图的主题
<android.support.design.widget.BottomNavigationView
    android:id="@+id/navigation"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginEnd="0dp"
    android:layout_marginStart="0dp"
    android:theme="@style/BottomNavigationTheme"
    app:menu="@menu/navigation" >
© www.soinside.com 2019 - 2024. All rights reserved.