Change the font of tab text in android design support TabLayout

前端 未结 18 1679
执念已碎
执念已碎 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

    Create a TextView from Java Code or XML like this

    
    
    

    Make sure to keep the id as it is here because the TabLayout check for this ID if you use custom textview

    Then from code inflate this layout and set the custom Typeface on that textview and add this custom view to the tab

    for (int i = 0; i < tabLayout.getTabCount(); i++) {
         //noinspection ConstantConditions
         TextView tv = (TextView)LayoutInflater.from(this).inflate(R.layout.custom_tab,null)
         tv.setTypeface(Typeface);       
         tabLayout.getTabAt(i).setCustomView(tv);
    }
    

提交回复
热议问题