AssetManager mgr=getAssets();
Typeface tf=Typeface.createFromAsset(mgr, "fonts/cube.ttf");
textView.setTypeface(tf);
The method above can modify font of the TextView, but I do not want to do it like this. My idea: The user can download the font on the internet and store it in the sd-card. Then the user can apply the font they just downloaded to the widget. I feel this method can reduce the size of the project. Any suggestions?
1.) Download "font.ttf" (Replace with your ttf file name) File to external storage through the internet.
2.) Do this.
Typeface typeface = Typeface.createFromFile(
new File(Environment.getExternalStorageDirectory(), "font.ttf"));
textView.setTypeface(tf);
Related
Can we set typeface at run time and .ttf file are coming from server means ttf file come from server and we have to set our font according that
Yes its possible. You can download the ttf file into external storage and create TypeFace from that file.
Typeface tf = Typeface.createFromFile(file);
here file should be the ttf file from server.
Yes its possible To set Custom font(s) from server.
Download font from server
Save to SD card
Use Typeface.createFromFile(String path)
textView.setTypeface(yourTypeface);
Code
TextView tv=(TextView)findViewById(R.id.custom);
Typeface face=Typeface.createFromFile(new File(Environment.getExternalStorageDirectory(), "font.ttf"));
tv.setTypeface(face);
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?
first place your font in assets folder then like:
gameResult = (TextView) findViewById(R.id.textViewResult);
Typeface type = Typeface.createFromAsset(getAssets(),"fonts/Kokila.ttf");
gameResult.setTypeface(type);
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);
Is it possible to use a custom font in android which is stored in the SD card? What I've seen so far indicates the font file must be in the assets folder. Please tell me I'm wrong.
Typeface.createFromFile() takes a String path or File.
Typeface typeface = Typeface.createFromFile(
new File(Environment.getExternalStorageDirectory(), "font.ttf"));
I have not tried it myself but the recipe states you might be able to do it by using the
Typeface.createFromFile(String path)
http://androidcookbook.com/Recipe.seam;jsessionid=A2DD7A11C804B7C7646DCA883AA452FC?recipeId=1141
I wanna create an application in android to install a Hindi Font. Can some one guide me how i can go about it ? is it possible ?
Add the font file you want to use in the assets folder of your Android application. Then you can load the font and use it like this:
AssetManager assetManager = getContext().getAssets();
Typeface tf = Typeface.createFromAsset(assetManager,"GILB.TTF");
TextView logo = (TextView)findViewById(R.id.logo);
logo.setTypeface(tf);
In this case, I've used the true type font Gill Sans Bold.
You cannot install a font on a device.
You can package a font as an asset with your application to be used by your application.
How to add additional font in android environment? I need to make a font like LCD with pale background numbers like this:
http://www.androidfreeware.net/img2/gps_speedometer_android_1.png
We at bangalore android developers group had done this for one of our project AutoMeter You can have a look at the code there in detail.
The code would look something like this
Typeface myTypeface = Typeface.createFromAsset(this.getAssets(),"DS-DIGIB.TTF");
waitingTimeView = (TextView) findViewById(R.id.WaitingTime);
waitingTimeView.setTypeface(myTypeface);
DS-DIGIB.TTF is the font put in the assets folder
public void setFontTextView(Context c, TextView name) {
Typeface font = Typeface.createFromAsset(c.getAssets(),"fonts/Arial.ttf");
name.setTypeface(font);
}
Download Arial font in ttf file formate and put in asset folder. Thats enough.
You want to use the android.graphics.Typeface class, which can create new Typefaces from assets or files.