3

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?

Rubens Mariuzzo
  • 28,358
  • 27
  • 121
  • 148
  • i think there is no way to use custom font from xml file . u will need to use `Typeface.createFromAsset` to use ur own font for application – ρяσѕρєя K Mar 08 '13 at 12:51

4 Answers4

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!

poitroae
  • 21,129
  • 10
  • 63
  • 81
0

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

Community
  • 1
  • 1
M Rajoy
  • 4,028
  • 14
  • 54
  • 111
0

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);
webmonkey
  • 1,083
  • 1
  • 15
  • 33
0

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.

Community
  • 1
  • 1
Munim
  • 2,626
  • 1
  • 19
  • 28