Android: How to determine why custom font is not working - android

I am using various custom fonts in a TextView.
Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/font_name.ttf");
TextView tv = (TextView) this.findViewById(R.id.MyText);
tv.setTypface(tf);
tv.setText("data to view in custom font");
This works for some fonts but not for all I want to use. The failed fonts do so silently. there are no exceptions or other failure indications. The text is displayed in the default font not in the custom font. It is clear that the fonts are not displayed, because the custom fonts I am trying to use are chess piece figurines.
All the fonts work in Word and LibreOffice Writer
How do I determine what is wrong with the font, so I might fix it.
Edits:fixed example code to add tv.setTypeface(tf); clarified what not working means.

Related

Font issue in TextView

I have a TextView which contains just one letter. The size of the text is calibrated so that the letter occupies entire TextView area. Now one of my users reported a problem that the letter does not fit properly into the TextView. From the attached screenshot I can see that she uses some kind of custom font on her Samsung S4 device. I am sure that's the problem. Here are some snapshots:
Custom font in a TextView over ImageView:
Custom font in the Status Bar:
Distorted letter N in my TextView:
Is there any way to make a TextView use standard android font ignoring any custom fonts that users applies? How can I install custom fonts on the emulator or Sony phone (do not have Samsung) and replicate the behavior?
Yes you can set custom fonts to your app. Make use TypeFace class.
Create a folder called fonts under assets folder and place all your fonts in it (Font format ttc or ttf. Folder name can be anything)
Within you onCreate method add the below code.
TextView mytextview= (TextView) findViewById(R.id.text_view_id);
// Loading Font Face. Replace with your font file name
Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/your_custom_font.ttf");
// Applying font
mytextview.setTypeface(tf);
Similar way you can have as many as TypeFace you require and also use the same TypeFace declared on as many as TextView you want.
This tutorial below very well explains your requirement and also provides screenshot for better assistance.
http://www.androidhive.info/2012/02/android-using-external-fonts/
Also kindly note that TypeFace has a lot of other options that you can play around with. You can refer the android docs to get an idea about them.
I hope it helped you.
Thanks!!
My advise:
Create a subfolder in your asset folder called fonts.
Put there the fonts you want to use (for example ttc, or ttf) Set
your TextView typeface. For example:
yourTextView.setTypeface(Typeface.createFromAsset(getContext().getAssets(), "fonts/yourFont.ttc"));
I hope it helps!!

How to set Gujarati joint word in Android?

I have created an android app, in that I want to set Gujarati joint word.
I use Shruti.ttf font.
I want to print -
નર્સિંગ
But it prints-
નર્ સંગિ
So, how to print proper.
My code is -
TextView tv_guj=(TextView)findViewById(R.id.tv_gujarati);
Typeface font = Typeface.createFromAsset(getAssets(), "Shruti.ttf");
tv_guj.setTypeface(font);
tv_guj.setText("નર્સિંગ");
Please try this sample and copy your text to this sample text view it will work and will show proper result as you want
https://www.dropbox.com/s/6pqg9otcli038ij/HindiFont.zip
Lohit-Gujarati font is working
you can use terafont of gujarati Fontface so it will be implemented.
Thanks

Android Arabic/Farsi Fonts

I am developing an Android aap that uses Arabic Fonts.
I have successfully display Arabic text by using "tahoma.ttf"
But problem is that these Arabic Fonts Didn't give a cool look.
So i wanted to change that Font Style. Is there any way of doing this ?
If you want to use external font do :
First step is to pick a font that you want to use.
Create a fonts folder in your assets directory and copy your font there.
To access your custom font,use the Typeface class in the Android SDK to create a typeface that Android can use, then set any display elements that need to use your custom font appropriately.
Unfortunately, you can no longer use layout XML for this, since the XML does not know about any fonts you may have tucked away as an application asset.You can do like this in your code:
Typeface tf = Typeface.createFromAsset(getAssets(),"fonts/BPreplay.otf");
TextView tv = (TextView) findViewById(R.id.CustomFontText);
tv.setTypeface(tf);
Note: Android does not seem to like all TrueType fonts.So, if you try to use a different font and it does not seem to be working, it may be that the font is incompatible with Android, for whatever reason.
You can see more details in these pages:
Fun with Fonts
Musings of the Bare Bones Coder/using custom fonts

Easiest way to use custom fonts? - android

the way i found for using custom fonts on my android app is using the below code
TextView txt = (TextView) findViewById(R.id.textView1);
Typeface font = Typeface.createFromAsset(getAssets(), "ABCD.TTF");
txt.setTypeface(font);
i've stored the ABCD.TTF in assets folder..
and ya it works, no probs in tat.. the thing is i have to add the above code for each and every texts,buttons,etc i have.. and its really a time consuming thing if theres lots of texts and buttons in various activity :(
what i need is an alternate method to do it, an easiest one to do it..
like using a single block of code not repeatative like the above to change the fonts for all the stuffs..
else doing it in the xml
or is there any way to add our custom font to the inbuilt typeface where normal,sans,serif,monospace are present.
like using a single block of code not repeatative like the above to change the fonts for all the stuffs..
There are a few ways of doing this already addressed in various StackOverflow answers. Here is that iterates over the children of a ViewGroup and apply a Typeface to all that implement TextView:
- https://stackoverflow.com/a/7580370/115145
else doing it in the xml
Sorry, this is not supported.
or is there any way to add our custom font to the inbuilt typeface where normal,sans,serif,monospace are present.
Sorry, this is not supported, except if you build your own firmware.
You can use simple EasyFonts third party library to set variety of custom font to your TextView. By using this library you should not have to worry about downloading and adding fonts into the assets/fonts folder. Also about Typeface object creation.
Simply:
TextView myTextView = (TextView)findViewById(R.id.myTextView);
myTextView.setTypeface(EasyFonts.robotoThin(this));

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

Categories

Resources