Android - How to change bottom navigation bar text's font family

后端 未结 11 1519
北荒
北荒 2020-12-14 00:27

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

11条回答
  •  时光取名叫无心
    2020-12-14 01:09

    For Kotlin Lover

    Create an extension class for custom asset font

        /**
          * Method for Bottom Navigation Font Family
          *@param view
          *
          * */
    private fun navigationTextFont(view: View) {
        if (view is ViewGroup) {
            for (i in 0 until view.childCount) {
                val child = view.getChildAt(i)
                navigationTextFont(child)
            }
        } else if (view is TextView) {
            view.typeface = Typeface.createFromAsset(this.assets, "fonts/roboto_bold.ttf")
        }
    }
    

    Now call this extension

       navigationTextFont(yourNavigationViewId)
    

    Good Luck

提交回复
热议问题