21 Mar 2013

Fonts Android / Custom Fonts.

In android by default the following fonts are available.
DEFAULT
DEFAUT_BOLD
SERIF
SANS-SERIF
MONO SPACE

The Typeface class is used to specify the style of a font. In this example i am creating a textview and apply the fonts to that textview.

      TextView tv = new TextView(this); 
      //For DEFAULT
      tv.setTypeface(Typeface.DEFAULT); 
      //For DEFAUT_BOLD
      tv.setTypeface(Typeface.DEFAULT_BOLD); 
      //For SERIF
      tv.setTypeface(Typeface.SERIF); 
      //For SANS-SERIF
      tv.setTypeface(Typeface.SANS_SERIF);  
      //For MONO SPACE
      tv.setTypeface(Typeface.MONOSPACE);

      //Custom Fonts
To create custom font first we have to download the font file (.ttf). Copy that file to Assest folder of your project.

      //Creation of custom font
      Typeface tf = Typeface.createFromAsset(getAssets(), "ABC.ttf");
      tv.setTypeface(tf);


i will be happy if you will provide your feedback or follow this blog. Any suggesion and help will be appreciated.
Thank you :)

No comments:

Post a Comment