0

I want to work with custom font for my app,so I need to get custom font from asset folder,and initialize that as a property in xml file.

android:fontFamily="fonts/PoiretOne-Regular.ttf"

I just tried this but ,xml won't reflect it.

thank you in advance.

Hari Enaganti
  • 359
  • 1
  • 4
  • 12

2 Answers2

1

Try this,

-Store fontname.ttf to fonts directory inside assets directory.

TextView myTextView = (TextView) findViewById(R.id.tv1);
Typeface myTypeface = Typeface.createFromAsset(getAssets(),
            "fonts/fontname.ttf");
myTextView.setTypeface(myTypeface);

Hope this will be helpful...thanks

sahu
  • 1,188
  • 10
  • 19
0

image

 //create instance
 Typeface tf;

 //initialize it
 tf = Typeface.createFromAsset(this.getAssets(), "fonts/light.TTF");

 //then set it on textview ,buttons ...
 duration.setTypeface(tf);

 //if you dont have asseste folder create like this in image!
ArtKorchagin
  • 4,801
  • 13
  • 42
  • 58
Sohail Zahid
  • 8,099
  • 2
  • 25
  • 41
  • thankq sir,but Is any chance to give typaface in XML itself,by that i need to reduce my code complexity – Hari Enaganti Jun 30 '15 at 09:58
  • for that purpose you have to create your class ......this might help you [http://stackoverflow.com/questions/11471640/set-custom-font-through-xml] – Sohail Zahid Jun 30 '15 at 10:13