How to use Custom font in eclipse? [duplicate] - android

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Android - Using Custom Font
i am creating an application in arabic
and have a custom font that i want to use
can someone tell me the code i should use in my java class
i tried this
TextView txt = (TextView) findViewById(R.id.custom_font);
Typeface font = Typeface.createFromAsset(getAssets(), "trado.ttf");
txt.setTypeface(font);
but the ending line that says font theres an error that says
Syntax error on token "font", VariableDeclaratorId expected after this token
Can someone help!

try this, as in adding this lol
TextView txt = (TextView) findViewById(R.id.custom_font);
Typeface font = Typeface.createFromAsset(this.getAssets(), "trado.ttf");
txt.setTypeface(font);

Save your custom font file in a folder fonts inside the assets folder.
for example:
assets/fonts/trado.ttf
and make sure your font extension (i.e ttf in your case) is in lower case.

Related

Set different font by default for TextView in Android [duplicate]

This question already has answers here:
How to change the font on the TextView?
(16 answers)
Closed 8 years ago.
I want to set a custom font by default for TextView in android app. Will i need to create custom view for this ? Or is there any other way to do it except for loading it from assets folder and applying them individually?
Is there a way that a custom font can be directly used in xml, just like "sans","serif"
In your asset folder create a folder named fonts and then access it like this :
TextView text = (TextView) findViewById(R.id.textview03);
Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/YourFile.otf");
text.setTypeface(tf);
First download the .ttf file of the font you need (urfont.ttf). Place it in the assets folder(Inside assest folder create new folder named "fonts" and place it inside it).
Typeface tf = Typeface.createFromAsset(getAssets(),
"fonts/urcustomfont.ttf");
TextView tv = (TextView) findViewById(R.id.CustomFontText);
tv.setTypeface(tf);
This question has previously been answered:
How to change the font on the TextView?
Default font is Droid Sans. Also can have Droid Sans Mono and Droid Serif. These can be changed through either using setTypeface, or through editing the android:typeface XML
As already stated, you can use custom fonts by the method described by AndroidWarrior but keep in mind licensing issues as well as the performance of your app if you add lots of custom fonts.

new locale in android (urdu/pakistan) [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Set Locale programatically
I am a beginner in android. making my first app, all i want to do is localize my app to urdu language/pakistan. what should i do.
Where I can get the list of all android locale?
This post may be helpful, code of Urdu - Pakistan is ur-PK, which may not be present for your use. List of all android locale can be found here or here. Also take a look at localization tutorial
If you want to use urdu font for showing text in a view(say TextView) then:
Code for setting custom font to TextView:
Assuming you have a urdu ttf font say(URDU.ttf) font in fonts folder under assets folder:
Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/URDU.ttf");
TextView tv = (TextView) findViewById(R.id.txtview);
tv.setTypeface(tf);
You might want to look this question. Also for urdu-pakistan you might get the code from here

Display malayalam text in my app [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
malayalam font in android?
I want to display Malayalam text in my app, is it possible? I have tried using typeface from gont file of malayalam language. But it doesn't work. Is there any other way to do it. Please give me some
suggestions,
Thanks in advance.
Get your required Malayalam font into your assets folder of your application. And, follow the below steps -
Just use this font to your TextView with Typeface like below code
Typeface typeFace = Typeface.createFromAsset(getAssets(),"malyalam.fnt");
and then add it to your textview like below
textView.setTypeFace(typeFace);
Get your malayalam fonts here -
Malayalam Fonts and Fonts for Malayalam
Hope this helps you.
Update
I just tested below code with one malayalam font. Its working fine. Try with that -
TextView t = (TextView)findViewById(R.id.textView1);
t.setText("മലയാളം");
Typeface typeFace = Typeface.createFromAsset(getAssets(),"AnjaliOldLipi.ttf");
t.setTypeface(typeFace);

How to use mathematical fonts in android?

I am creating an app which uses math fonts like lambda,integral etc in android. And how could i use an keyboard for that? plz help nothing found on google
If you have a .ttf font file with your symbols, place it in the /assets folder then use it on a TextView like this:
Typeface font = Typeface.createFromAsset(getAssets(), "font.ttf");
TextView tv = (TextView) findViewById(R.id...);
tv.setTypeface(font);
As for using the keyboard see:
http://www.addictivetips.com/mobile/create-your-own-custom-keyboard-for-android-devices/ and creating custom android keyboard layout

Custom Font Issue In Android

I am trying to use custom font in android. I have written java code as given below.
TextView txt = (TextView) findViewById(R.id.customfont);
Typeface font = Typeface.createFromAsset(getAssets(), "fonts/Molot.otf");
txt.setTypeface(font);
where I have stored the custom font in "./assets/fonts/" folder.
But, I am getting nullpointerexception on the 3rd line.
Can anybody give me the solution for this issue? Thanks
Android supports only TTF font type not OTF. Check this link
"RuntimeException: native typeface cannot be made" when loading font
Android supports OTF as well. Your font may be corrupt.
Download delicious font from www.exljbris.com/delicious.html. It is an otf font and it works for me.
Try this
Typeface font = Typeface.createFromAsset(getAssets(), "/fonts/Molot.otf");

Categories

Resources