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

后端 未结 11 1494
北荒
北荒 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:04

    public void setNavigationTypeface() {
            final Typeface avenirHeavy = Typeface.createFromAsset(this.getAssets(), "font2/Avenir-Heavy.ttf"); //replace it with your own font
            ViewGroup navigationGroup = (ViewGroup) bottomNavView.getChildAt(0);
            for (int i = 0; i < navigationGroup.getChildCount(); i++) {
                ViewGroup navUnit = (ViewGroup) navigationGroup.getChildAt(i);
                for (int j = 0; j < navUnit.getChildCount(); j++) {
                    View navUnitChild = navUnit.getChildAt(j);
                    if (navUnitChild instanceof BaselineLayout) {
                        BaselineLayout baselineLayout = (BaselineLayout) navUnitChild;
                        for (int k = 0; k < baselineLayout.getChildCount(); k++) {
                            View baselineChild = baselineLayout.getChildAt(k);
                            if (baselineChild instanceof TextView) {
                                TextView textView = (TextView) baselineChild;
                                textView.setTypeface(avenirHeavy);
                            }
                        }
                    }
                }
            }
        }
    

提交回复
热议问题