edi233
edi233

Reputation: 3031

How can I set chosen font in textview

I have a question. How Can I set font for example: Harrington in textview. I use:

Typeface type = Typeface.createFromFile("C:/Fonts/Kokila.ttf");
gameResult.setTypeface(type);
gameResult = (TextView) findViewById(R.id.textViewResult);

but this solution is not working. Any ideas?

Upvotes: 0

Views: 519

Answers (2)

ρяσѕρєя K
ρяσѕρєя K

Reputation: 132992

first place your font in assets folder then like:

enter image description here

gameResult = (TextView) findViewById(R.id.textViewResult);
Typeface type = Typeface.createFromAsset(getAssets(),"fonts/Kokila.ttf"); 
gameResult.setTypeface(type);

Upvotes: 2

Mimminito
Mimminito

Reputation: 2853

You are trying to access the font from your PC! Your phone does not have access to the 'C:/' drive of your PC, and therefore cannot load the font. You need to place the Font into the Assets folder of your application, and then read it from there.

You can read a file from the Assets folder using

context.getAssets().open(fileName);

Upvotes: 2

Related Questions