Change the font of tab text in android design support TabLayout

前端 未结 18 1721
执念已碎
执念已碎 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条回答
  •  孤独总比滥情好
    2020-11-27 14:20

    My 2p, Kotlin with reference checking, applicable everywhere as it will stop if something is wrong.

    private fun setTabLayouFont(tabLayout: TabLayout) {
        val viewGroupTabLayout = tabLayout.getChildAt(0) as? ViewGroup?
        (0 until (viewGroupTabLayout?.childCount ?: return))
                .map { viewGroupTabLayout.getChildAt(it) as? ViewGroup? }
                .forEach { viewGroupTabItem ->
                    (0 until (viewGroupTabItem?.childCount ?: return))
                            .mapNotNull { viewGroupTabItem.getChildAt(it) as? TextView }
                            .forEach { applyDefaultFontToTextView(it) }
                }
    }
    

提交回复
热议问题