更改标签文本的字体在Android的设计支持TabLayout [英] Change the font of tab text in android design support TabLayout
问题描述
我想工作,对新的 TabLayout
从Android的设计库。
I'm trying to work on the new TabLayout
from the android design library.
我希望标签的文本更改为自定义字体。而且,我试图寻找一些造型与 TabLayout
,但最终以<一个href="https://android.googlesource.com/platform/frameworks/support.git/+/master/design/res/values/styles.xml">this.
I want to change tab text to custom font. And,I tried to search some styling related to TabLayout
,but ended up to this.
请指导我如何更改标签的文本字体。
Please guide how can I change the tab text fonts.
推荐答案
如果您使用的是TabLayout,你想,你必须添加一个新的循环,像这样的previous解决方案来改变字体:
if you are using TabLayout and you want to change the font you have to add a new for loop to the previous solution like this:
private void changeTabsFont() {
ViewGroup vg = (ViewGroup) tabLayout.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.getInstance().getTypeFace(), Typeface.NORMAL);
}
}
}
}
请参阅本<一个href="http://stackoverflow.com/questions/12665186/change-font-style-in-action-bar-tabs-using-sherlock">Change使用夏洛克字体样式在操作栏标签
refer this Change font style in Action Bar Tabs using Sherlock
这篇关于更改标签文本的字体在Android的设计支持TabLayout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!