简体   繁体   中英

How to set path for typeface for a font file in android

I am using typeface class to set the font Monotype corsiva for an edittext

 EditText ed=(EditText) findViewById(R.id.editexthead);
 String path="C:\\MTCORSVA.TTF";
 Typeface tf=Typeface.createFromFile(path);
 ed.setTypeface(tf);

The program force closes with an exception Is there any other way to set the path..

And when i try to manually store a .TTF on sdcard it doesn't show up the file... any reason for that. I don't want to use assets folder to set the font ... anybody with the solution .. ?? Please HELP

Store the font file in the assets directory and get to it with this code:

 Typeface font = Typeface.createFromAsset(getApplicationContext().getAssets(), "MTCORSVA.TTF")
 view.setTypeface(font);

Why do you not want to store it in the assets folder? That's what it's for. Regardless, you can't reference your local hard drive for it.

(also, personal opinion, Monotype Corsiva is a horrible, horrible font)

EDIT: So I would add, you should be able to do it the way you're doing it, you just can't use your local hard drive. Just get a reference to your TypeFace as a File , depending on where you are saving them (eg Environment.getExternalStorageDirectory() ) and use Typeface.createFromFile(file) .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM