android font size of tabs

后端 未结 7 1481
滥情空心
滥情空心 2020-11-29 13:25

i ask this quest for a few time ago , but i get no solutions :( my problem is, that i have an android app with a tab activity, where i have to set the font size of my tabs,

7条回答
  •  时光取名叫无心
    2020-11-29 13:33

    #If you dont want to use style.xml and do by prgramatically the Use this in your xml layout. #
    
    
                
    
    
    #In your activity or fragment use this method#
    
     private void changeTabsFont() {
            Typeface font = Typeface.createFromAsset(getActivity().getAssets(), "fonts/"+ Constants.FontStyle);
            ViewGroup vg = (ViewGroup) tab_layout.getChildAt(0);
            int tabsCount = vg.getChildCount();
            for (int j = 0; j < tabsCount; j++) {
                ViewGroup vgTab = (ViewGroup) vg.getChildAt(j);
                int tabChildsCount = vgTab.getChildCount();
                for (int i = 0; i < tabChildsCount; i++) {
                    View tabViewChild = vgTab.getChildAt(i);
                    if (tabViewChild instanceof TextView) {
                        ((TextView) tabViewChild).setTypeface(font);
                        ((TextView) tabViewChild).setTextSize(15);
    
                    }
                }
            }
        }
    

    This code works for Tablayout change text color,type face(Font style) and also Text size. IF this works for you also then make correct so other user can easily solve his/her problem

提交回复
热议问题