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
  • 27,091
  • 26
  • 115
  • 147
  • 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
  • 20,729
  • 9
  • 59
  • 80
0

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

Community
  • 1
  • 1
Gabriel Sanmartin
  • 3,804
  • 14
  • 51
  • 105
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,063
  • 17
  • 32
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,476
  • 1
  • 18
  • 27