0

In TextView, I can use android:letterSpacing="0.1" to set letter spacing

But this is not work in BottomNavigationView

I use this code to set font style of BottomNavigationView

I guess I can also set letter spacing here, but I cannot find related method

How to set the letter spacing?

<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)
}

1 Answer 1

2

I was able to do it in this way:

  1. Create a style where the parent is Widget.Design.BottomNavigationView
<style name="BottomNavigationTheme" parent="Widget.Design.BottomNavigationView">
    <item name="android:letterSpacing">0.1</item>
</style>
  1. Set the style as theme of your Bottom Navigation View
<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" >

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.