Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add custom font for complete android application

In my application I need to use helvetica font for all the textviews and edit-text fields. Is there any way to do this other than using settypeface method for every textview ? Any suggestion would be a great help.

Thanks in advance !

like image 503
Chrishan Avatar asked Aug 03 '11 12:08

Chrishan


People also ask

How do I create a TTF file on Android?

1 - Right-click the res folder and go to New > Android resource directory. The New Resource Directory window appears. 2 - In the Resource type list, select font, and then click OK. 3 - Add your font files in the font folder just by a simple copy and paste.

How do I use OTF files on Android?

To change font styles in GO Launcher, copy the TTF or OTF font files on your phone. Long press on the home screen and select GO Settings > Font > Select Font. Pick the font you want or tap Scan to add files stored on your device. This won't be a system-wide change but will include the menus and app icons.


1 Answers

I figured it out by my self. This is the code I used. I create custom TextView which has custom font as default font.

public class MyTextView extends TextView {      public MyTextView(Context context, AttributeSet attrs, int defStyle) {         super(context, attrs, defStyle);         init();     }      public MyTextView(Context context, AttributeSet attrs) {         super(context, attrs);         init();     }      public MyTextView(Context context) {         super(context);         init();     }      private void init() {         Typeface tf = Typeface.createFromAsset(getContext().getAssets(), "font/chiller.ttf");         setTypeface(tf ,1);      }  } 
like image 143
Chrishan Avatar answered Oct 16 '22 06:10

Chrishan