I have created a bottom bar navigation in my android page. But now I want to apply the custom font-family in bottom navigation texts.
This is the bottom navigation c
Kotlin language:
1: Create a file with a custom name, ex: BottomNavigationViewExtension.kt
2: Put the code below:
import android.graphics.Typeface
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import com.google.android.material.bottomnavigation.BottomNavigationView
fun BottomNavigationView.changeNavTypeface(typeface: Typeface) {
val view: View = this
checker(view, typeface)
}
private fun checker(view: View, typeface: Typeface) {
if (view is ViewGroup) {
for (i in 0 until view.childCount) {
val child = view.getChildAt(i)
checker(child, typeface)
}
} else if (view is TextView) {
view.typeface = typeface
}
}
3: Usage:
navView.changeNavTypeface(
Typeface.createFromAsset(
assets,
"fonts/IRANSansMobile.ttf"
)
)