1

From android 4.1 / 4.2, the following Roboto font families are available:

 android:fontFamily="sans-serif"           // roboto regular
 android:fontFamily="sans-serif-light"     // roboto light
 android:fontFamily="sans-serif-condensed" // roboto condensed
 android:fontFamily="sans-serif-thin"      // roboto thin (android 4.2)

But I need something like that for version 4.0.3. Does someone know how to do this?

silvia_aut
  • 1,481
  • 6
  • 19
  • 33

3 Answers3

2

As you say before V4.2 sans-serif-thin is not available for devices on versions below that.

But you can put a font file with your apk by putting a .ttf or .otf file into your /assets folder and using this code:

TextView txt = (TextView) findViewById(R.id.custom_font);  
Typeface font = Typeface.createFromAsset(getAssets(), "Chantelli_Antiqua.ttf");  
txt.setTypeface(font);

here is the full example: http://mobile.tutsplus.com/tutorials/android/customize-android-fonts/

You can also get the sans-serif-thin font here: http://www.fontsquirrel.com/fonts/roboto

string.Empty
  • 10,393
  • 4
  • 39
  • 67
1

From this SO question

Android doesn't allow you to set custom fonts from the XML layout. Instead, you must bundle the specific font file in your app's assets folder, and set it programmatically. Something like:

TextView textView = (TextView) findViewById(<your TextView ID>);
Typeface typeFace = Typeface.createFromAsset(getAssets(), "<file name>");
tv.setTypeface(typeFace);

Note that you can only run this code after setContentView() has been called. Also, only some fonts are supported by Android, and should be in a .ttf (TrueType) or .otf (OpenType) format. Even then, some fonts may not work.

EDIT

enter image description here

And here you can download .ttf files.

Community
  • 1
  • 1
Ketan Ahir
  • 6,678
  • 1
  • 23
  • 45
0

install/keep font in asset folder and asign it to the text view programatically.

Typeface mDesiredFace= Typeface.createFromAsset(getAssets(),"sans-serif.ttf");
textView.setTypeface(mDesiredFace);
Pradip
  • 3,189
  • 3
  • 22
  • 27