Android custom typeface in chinese text - android

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.

Related

Adding costum font to android in font family xml

In the android guides for Fonts in XML, they give the example of font family XML you create by adding:
android:font="#font/lobster_regular"
Which I think its the font you added to your assets/font folder. But when i try it I don't get it why it isn't able to find the font I've added. It only fins sans, serif and mono-space. Anyone have a clue what it might be the problem?
I know there are other ways to add a custom font, but due to the material calendar that I want to use, I need it to define in the styles XML, only way to customize it. I tried calligraphy lib, but does not help.
Using typeface you easily set font family
Typeface type = Typeface.createFromAsset(getAssets(),
"fonts/fontname");
now set this typeface to your textview
tv.setTypeface(type);
Add this to your activity code:
TextView tv = (TextView) findViewById(R.id.appname);
Typeface face = Typeface.createFromAsset(getAssets(),
"fonts/fontname");
tv.setTypeface(face);
Note that for this you'll have to create a fonts folder at app/src/main/assets

How to set Marathi font to text view in android?

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 want to change the font on part of my String variable (textview) with a font located in assets

I have textview which contains a string that i want a specific part of it to be red and use a different font from the rest of the text this is what i've tried
in the onCreate method i put a different font on the whole textview
Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/RobotoCondensed-Light.ttf");
mn.setTypeface(tf);
and after that Si is part of a for loop and when a case is matched i want to change the font
Si+="<font face='RobotoCondensed-Bold' color='#8B2121'><b>"+SiArray[0]+"</b></font>";
mn.setText(Html.fromHtml(Si));
mn.setTextSize(19.5f);
so RobotoCondensed-Bold is a font that i have in assets folder in my android project how to use that font instead of the regular Ariel....etc...etc...

Android Typeface createFromAsset

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()

Set the fonts toa text in android

Hi want to change the font type to atext according to spinner selection like arial balck,Thlist etc.any one have idea ? suggest me
You should change the typefaces of your text views. You can specify a variable:
Typeface typeface = Typeface.DEFAULT;
Then when the user chooses another font you reinitialize this variable, using the built-in typefaces, or loading your own from .ttf files, that you can place in assets/fonts directory. Loading own fonts can be done with this call:
typeface = Typeface.createFromAsset(context.getAssets(),
"fonts/font.ttf");
This should do it.

Categories

Resources