I have one application in Which I want to change font of text in whole application.
Is there anyway to change font of application Programmatically or with xml in manifest.?
Change FontFace of application
917 views Asked by Ando Masahashi At
4
There are 4 answers
0
On
Create fonts folder in asset and paste the fonts whatever you want to paste.
Create one class. Name it Typesafe.java
public enum TypeSafe {
HELVETICANEUELTCOMBD,
HELVETICANEUELTCOMBDCN,
HELVETICANEUELTCOMCN,
}
After that create one method in your Activity or if you have the Utility class.
public void setTypeface(TextView textView, TypeSafe type, AssetManager assetManager){
if (TypeSafe.HELVETICANEUELTCOMBD.equals(type)) {
final Typeface typeface = Typeface.createFromAsset(assetManager, "fonts/HelveticaNeueLTCom-Bd.ttf");
textView.setTypeface(typeface);
} else if (TypeSafe.HELVETICANEUELTCOMBDCN.equals(type)) {
final Typeface typeface1 = Typeface.createFromAsset(assetManager, "fonts/HelveticaNeueLTCom-BdCn.ttf");
textView.setTypeface(typeface1);
}
}
Call these method in your activity.
setTypeface(yourtextView, TypeSafe.HELVETICANEUELTCOMLT, getAssets());
The easiest way to do it is creating your own TextView:
now, you can use it anywhere in your xml:
<com.your.package.MyTextView ... >just like normal textviewsIt might be improved by caching the Typeface, so you don't have to create it again with every Reference to your TextView.