android custom font for tabs

守給你的承諾、 提交于 2019-12-22 11:28:41

问题


I would like to have a custom font for my tabs. Here's what I have tried:

<style name="CustomTabWidgetText" 
parent="@android:style/TextAppearance.Widget.TabWidget">
  <item name="android:textSize">14sp</item>
  <item name="android:typeface">@assets/fonts/heartbre</item>
  <item name="android:textStyle">bold</item>
</style>

But I got an error in <item name="android:typeface">@assets/fonts/heartbre</item>.

Has anybody here tried customizing the font of tabs?


回答1:


The only (currently) available way to set Fonts is to do it programatically:

TextView tv= (TextView)findViewById(R.id.custom);
Typeface face=Typeface.createFromAsset(getAssets(), "fonts/heartbre.ttf");
tv.setTypeface(face);

However, I hope there will be a xml-way to do it some day!




回答2:


You can only define custom fonts by code or through styleable attributes in a custom object extending TexView like here




回答3:


No possibility to add manually from XML (as far as I know!). You have to do it within your code:

Typeface typeface = Typeface.createFromAsset(getAssets(), "fonts/heartbre.ttf");
textView.setTypeface(typeface, Typeface.BOLD);



回答4:


Please refer to this question setting custom font for sherlock action bar tab android and check my answer. So far the solution I posted there is the best working one in all cases. Hope it will help.



来源:https://stackoverflow.com/questions/15294372/android-custom-font-for-tabs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!