Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom Fonts in Android

I have already read some articles and searched on Google, but I failed to do it.

My problem is regarding the font-face.

In Android, there are only 4 attributes in "android:typeface": Normal, Sans, Serif, Monospace.

So what do I have to do to use "Verdana" in my application?

Please suggest me a correct way to use this font in my Android application.

like image 379
Paresh Mayani Avatar asked Jul 08 '10 12:07

Paresh Mayani


People also ask

How do I add fonts to Android keyboard?

Long press on the home screen and select GO Settings. Choose Font–>Select Font. Pick the font you want or tap Scan to add files stored on your device.

Can you get different fonts for Android?

Tap “Font Size and Style” if you're a Samsung device owner. This may appear as “Font” or another variation on other phones and tablets. In the “Font Size and Style” menu, tap the “Font Style” button. You'll have a list of pre-installed font styles available for you to choose from.


2 Answers

This is a simple example... create a folder in the root of your project called assets/fonts/ then paste the TTF font file (in this case Verdana.ttf). Then, if you want to apply that font to, say a TextView, do the following:

import android.graphics.Typeface;

public class FontSampler extends Activity {
  @Override
  public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.main);

    TextView tv=(TextView)findViewById(R.id.custom);
    Typeface face=Typeface.createFromAsset(getAssets(),
                                          "fonts/Verdana.ttf");

    tv.setTypeface(face);
  }
}

This example was taken from the ComonsWare book (written by Mark Murphy). You can download the full example from GitHub.

like image 164
Cristian Avatar answered Oct 21 '22 07:10

Cristian


You can use PixlUI at https://github.com/neopixl/PixlUI

import their .jar and use it in XML

 <com.neopixl.pixlui.components.textview.TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/hello_world"
    pixlui:typeface="GearedSlab.ttf" />
like image 4
guest2343sdfdfs Avatar answered Oct 21 '22 07:10

guest2343sdfdfs