Use external fonts in android

I want to use external fonts in my application. I tried adding new fonts using asset managers, but that didn't work.

Typeface face; face = Typeface.createFromAsset(getAssets(), "font.otf"); textview.setTypeface(face); 

but the text did not show ...

Help plz.

+56
android fonts android-widget
Sep 15 '09 at 9:58
source share
7 answers

AFAIK, Android does not support OpenType. Use the TrueType font instead.




UPDATE: Obviously, OpenType is now supported, at least in several ways. It was not initially supported, so you need to thoroughly test the font on any version of Android supported by your application.

+62
Sep 16 '09 at 0:37
source share

To easily access our font, we need to associate it with our application so that our code can subsequently download it. To do this, we create the Fonts folder in our direct assets

It could be your .xml

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:id="@+id/DefaultFontText" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textSize="30sp" android:text="Here is some text." /> <TextView android:id="@+id/CustomFontText" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="30sp" android:text="Here is some text."> </TextView> 

Write the following code in your .java class

 Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/BPreplay.otf"); TextView tv = (TextView) findViewById(R.id.CustomFontText); tv.setTypeface(tf); 
+12
Mar 08 '13 at 12:07 on
source share

Android supports OTF (I'm not sure which SDK version it is from, but it definitely works with 1.6), I used the typewriter OTF font for some time, but the rendering was nowhere as accurate as the TTF version I ended up (via online font converter). The baseline was everywhere (some letters were 2 pixels higher than others), and on LDPI phones such as HTC Wildfire, the problem increased significantly due to large pixels.

+9
Jan 19 '11 at 11:20
source share

I had the same problem. My font also did not work on android, but I needed to work. Using the font editor, I copied the characters from my font to the font that comes with the FontSampler example from Android-src-2_1. It worked great.

Although I will admit that my method was questionable in terms of intellectual property, I did not actually use the original font, since all the characters were replaced, and all links to the old font, which was also replaced, I tried to “look” at how two fonts were detected, but matching all font matches didn’t work either. So in ned, I used the skeleton of the original font as a template for the new font.

+1
Jan 22
source share

android supports both otf and ttf formats, I tested both of them.

 tv3 = (TextView)findViewById(R.id.tv1); Typeface typeFace = Typeface.createFromAsset(getAssets(), "fonts/TRAJANPRO-BOLD.OTF"); tv3.setTypeface(typeFace); 

this is the step i used for english and local languages

+1
Nov 12 '13 at
source share

Use Fontinator It supports OTF stand and TTF Fonts

This is an Android library that facilitates the use of custom fonts.

https://github.com/svendvd/Fontinator

+1
Nov 30 '14 at 10:45
source share

You can use a simple third-party EasyFonts library to define a set of custom fonts for your TextView . Using this library, you do not have to worry about downloading and adding fonts to the assets / fonts folder. Also about creating a Typeface object.

It provides the following facets of fonts.

  • Roboto
  • Droid serif
  • Droid robot
  • Liberty
  • Fun raiser
  • Android Nation
  • Green avocado
  • Confession

Simply:

 TextView myTextView = (TextView)findViewById(R.id.myTextView); myTextView.setTypeface(EasyFonts.robotoThin(this)); 
-3
Jun 25 '15 at 18:43
source share



All Articles