问题
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