Skip to content

Instantly share code, notes, and snippets.

@babedev
Last active March 22, 2018 14:23
Show Gist options
  • Save babedev/146e2de28570ef53b881ec3d371ad83f to your computer and use it in GitHub Desktop.
Save babedev/146e2de28570ef53b881ec3d371ad83f to your computer and use it in GitHub Desktop.
Set font by resource ID got BottomNavigationView
fun BottomNavigationView.setFont(@FontRes rId: Int) {
val menuView = this.getChildAt(0) as BottomNavigationMenuView
val menuCount = menuView.childCount
(0 until menuCount).forEach {
val itemView = menuView.getChildAt(it) as BottomNavigationItemView
val titleView = itemView.getChildAt(1) as BaselineLayout
val smallLabel = titleView.getChildAt(0) as TextView
val largeLabel = titleView.getChildAt(1) as TextView
smallLabel.typeface = ResourcesCompat.getFont(context, rId)
largeLabel.typeface = ResourcesCompat.getFont(context, rId)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment