I have textview. I could not show japanese characteristics. So downloaded font to Assets/fonts folder. I tried this code
Typeface tf = Typeface.createFromAsset(getAssets(),
"fonts/ipag.ttf");
TextView tv=(TextView) findViewById(R.id.name);
tv.setTypeface(tf);
But application not working. What should be changed?
This code has work for me:
first declare the font:
Typeface font;
second inside the onCreate:
font = Typeface.createFromAsset(getAssets(), "myfont.ttf");
third: also inside the onCreate:
myTest = (Button) findViewById(R.id.myTest);
myTest.setTypeface(font);
My application can change the languaje and japanesse in one of those, and it works well.
This is the font used:
http://wowslider.com/styles/miso-bold-webfont.ttf.
by the way, the font is inside the Assets folder.
Related
I am developing android application in Marathi language,
for that i want to set Marathi font to text view.
So please let me know how to set that
Thanking you..
Put your font in assets folder, then create new Typeface from it
Here is an example
TextView txt = (TextView) findViewById(R.id.custom_font);
Typeface font = Typeface.createFromAsset(getAssets(), "SomeFont.ttf");
txt.setTypeface(font);
First of all put your fonts in assests folder in your project.
then in textview in java file where you want to put marathi, use this code:
Typeface mfont = Typeface.createFromAsset(getAssets(), "roboto_light.otf");
<your Textview>.setTypeface(mfont);
Download marathi fonts and save it in assests folder and set typeface using that font.
Sample:
TextView textView = (TextView)findViewById(R.id.textview);
Typeface tf = Typeface.createFromAsset(getAssests(), "name_of_font.ttf");
textView.setTypeface(tf);
you need to pass unicode character like\u... to you textview text.
you can use converter to convert the language. Or can take a look http://www.unicodeonline.com/
For getting the exact value you can pass your unicode into
ResourceBundle.getBundle(unicodestoragelocation,locale).getString(UnicodeValue)
I Have a Custom View which draws text onto the Canvas.
I want to change the font to a font stored in the assets folder.
I am using Android Studio so I created a folder src/main/assets and placed my ttf files in there.
Paint txt = new Paint()
Typeface font = Typeface.createFromAsset(getAssets(), "robotobold.ttf");
txt.setTypeface(font);
Problem is Android Studio doesn't recognize getAssets() inside my Custom View, however, it recognizes it inside my Activity. I have tried passing Typeface through from my Activity but when I do it it doesn't change the font.
You can use your View's getContext() method to get the current Context, then use it to get the assets:
Typeface font = Typeface.createFromAsset(getContext().getAssets(), "robotobold.ttf");
First of all, you have to keep your assets folder inside your project and not inside src/main.. And then, create a folder called fonts inside assets. then, put the specific font typeface ttf files inside it.You can use the font typeface in coding like:
Typeface type = Typeface.createFromAsset(getAssets(),"fonts/filename.ttf");
textview.setTypeface(type);
created a folder src/main/assets and placed font files in there.
in Activity
Typeface font = Typeface.createFromAsset(getAssets(), "Mukta-Regular.ttf");
tv.setTypeface(font);
in Fragment
Typeface.createFromAsset(getActivity().getAssets(), "Mukta-Regular.ttf");
tv.setTypeface(font);
In order to reuse typefaces in my projects I create a class full of typeface methods, this way I dont have to create a new typeface every time.
I call the class FontClass and in the class there is a method for each typeface I need to use e.g:
public static Typeface getOpenSansRegular(Context c){
return Typeface.createFromAsset(c.getAssets(), "OpenSans-Light.ttf");
}
Then I can use them like so:
TextView text = (TextView) findViewById(R.id.textview);
text.setTypeface(FontClass.getOpenSansRegular(getApplicationContext());
You have to place your assets folder inside "Project" folder and not in the "src" folder. You have placed your font in the "src/main/assets/robotobold.ttf" that's why it is not working. You need to place it like this "/assets/robotobold.ttf".
Typeface robo = Typeface.createFromAsset(getActivity().getAssets(), "fonts/Roboto-Thin.ttf");
My mistake was adding the line
Typeface mFont = Typeface.createFromAsset(this.getAssets(), "abc.ttf");
before onCreate()
I am trying to change typeface in a Textview which shows a chinese text.
My code is:
chinesetext = (TextView)findViewById(R.id.textChinese);
Typeface tf = Typeface.createFromAsset(getAssets(),"fonts/DFXSM1B.ttf");
chinesetext.setTypeface(tf);
DFXSM1B.ttf is in my assets/fonts folder.
I am unable to see the textview typeface changed.
How can I change to a custom typeface in a chinese text ?
I am using paint to set typeface, it dosen't work for chinese text...
I used the font family is 思源宋体 Medium
and my code like this: (that is very simple)
var typeface = Typeface.createFromAsset(context.assets, "fonts/font1.otf")
paint.typeface = typeface
All the files in asset folder must have lower-cased names.
Rename the file in lower case (dfxsm1b.ttf) and it must work.
I am new to android development, I need to implement Rich text Editor in my Application. So i googled and found some solutions. I am using this solution:
http://code.google.com/p/android-richtexteditor/source/browse/?r=4#svn/trunk/src/net/sgoliver
It supports the Bold, Italic and Underline in it. Now I want to change the font-style of selected text in EditText, How do i do that?
I know how to set the font-style for all the text in EditText. Suggestions will be appriciated!
Copy the font files (*.ttf) to the assets folder of your application.
Consider I have copied the font file "verdana.TTF" to the assets folder, then the following code will set the font to verdana
EditText et=(EditText) findViewById(R.id.editText1);
Typeface tf = Typeface.createFromAsset(getAssets(),"verdana.TTF");
et.setTypeface(tf);
Hope you got the solution
editText.setTypeface(Typeface.SERIF); as like as TextView.
Typeface tf = Typeface.createFromAsset(getAssets(),"fonts/Comic.ttf");
EditText et = (EditText)findViewById(R.id.et);
et.setTypeface(tf);
you can place ttf file in assets and set font style here
try this code..create font folder like this assets/font and put your font file in it..
edittxt = (EditText) findViewById(R.id.edittxt);
Typeface myTypeface = Typeface.createFromAsset( this.getAssets(), "font/YOURFONT.otf");
edittxt.setTypeface(myTypeface);
I am developing application which is having Gujarati font in text-view but my problem is that in text-view it shows the box instead of Gujarati font i have tried by "TypeFace" and text is at string.xml but it is not working please help me i have to submit on tuesday at school so please please help me
Thank you in advance
TextView cap = (TextView) view.findViewById(R.id.caption);
Typeface tf = Typeface.createFromAsset(getAssets(),"fonts/gujaratifont.ttf");
cap.setTypeface(tf);
cap.setText(R.string.gujarati);
Drop your file in assets Folder.
Try to do like this. getResources().getString(R.string.gujarati);
Its one reason is because Resources could not get to the TextView. Just Check it out.
TextView cap = (TextView) view.findViewById(R.id.caption);
Typeface tf = Typeface.createFromAsset(getContext().getAssets(),"fonts/gujaratifont.ttf");
//(or)
Typeface tf = Typeface.createFromAsset(getContext().getAssets(),"gujaratifont.ttf");
cap.setTypeface(tf);
cap.setText(R.string.gujarati);
and place your font file in assets folder.
i.e., create a folder with name fonts in assets folder and place that gujarati font in fonts folder.
if you want gujarati font download it from HERE
TextView mtxt = (TextView) findViewById(R.id.action_settings);
Typeface face1 = Typeface.createFromAsset(getAssets(),
"Lohit-Gujarati.ttf");
mtxt.setTypeface(face1);
mtxt.setText("પૂર્વ વડાપ્રધાન રાજીવ ગાંધી");