Change the font of tab text in android design support TabLayout

前端 未结 18 1675
执念已碎
执念已碎 2020-11-27 13:38

I\'m trying to work on the new TabLayout from the android design library.

I want to change tab text to custom font. And,I tried to sear

18条回答
  •  -上瘾入骨i
    2020-11-27 14:20

    Kotlin extension that worked for me:

    fun TabLayout.setFont(font: FontUtils.Fonts) {
        val vg = this.getChildAt(0) as ViewGroup
        for (i: Int in 0..vg.childCount) {
            val vgTab = vg.getChildAt(i) as ViewGroup?
            vgTab?.let {
                for (j: Int in 0..vgTab.childCount) {
                    val tab = vgTab.getChildAt(j)
                    if (tab is TextView) {
                        tab.typeface = FontUtils.getTypeFaceByFont(FontUtils.Fonts.BOLD, context)
                    }
                }
            }
        }
    }
    

提交回复
热议问题