Display unicode characters in TextView Android - android

There are a number of posts all over the internet on this topic, however none of them have been able to isolate and solve the problem.
I am trying to show some special UTF-8 encoded symbols stored in a SQLite database using a TextView, however all it shows is boxes. I understand what this means is that right font is not installed. But when I print those symbols using Arial font on Mac it works.
I am trying to use an Arial typeface on the device and the emulator.
Any advise.

It works on your Mac because the font used by your mac contains those special characters. It would be impossible to create a fontfile that contains all characters defined in unicode. Chinese fonts are a good example: none of them contain all of the ~60.000 known Chinese characters because the font file would be huge and unusable.
You could try using the font from your Mac on android (might be copyright issues - try finding a free font that contains the characters: package the (ttf) file in your application, for example in the /assets folder, and then in your application load that font with
TypeFace typeFace = Typeface.createFromAsset(assetmanager,"fontfile.ttf");
You can then use this in a TextView like so:
TextView view = (TextView) findById(R.id.mytext);
view.setTypeFace(typeFace);

If I'm understanding your situation correctly, you might want to consider the StringEscapeUtils.unescapeXml() method. It's in the common-lang.jar file available here: http://commons.apache.org/lang/
It will take encoded symbols (for example ' for an apostrophe) and get you to a proper character.

Related

Encoding Issue in Android String

Encoding Problem in android String
Web service return below string response
ãñøþ1219
but i getting response like ����1219
I am using below code to convert but it is not working
URLEncoder.encode(result, "UTF-8");
Please Help Me how i can fix this problem
Thanks In Advance
you must use Unicode font in order to display correctly Unicode text.
Most Android devices do not come with a complete set of Unicode fonts. Also in order to display Unicode text in a way that can be read properly you need to include a proper font for the script concerned.
Hence you can try as follows :
Typeface tf =Typeface.createFromAsset(getApplicationContext().getAssets(), "your_font.ttf");
text.setTypeface(tf,Typeface.BOLD);
text.setText(Html.fromHtml(your_text_with_unicode));
When you are getting response like ����1219, it is a font problem. When Android renders symbols as empty squares or the squares shown in above response,it means that Unicode support is working, but the font does not have those symbols. Adding to that the complex scripts like Indic scripts (e.g. Devanagari) require special rendering engine on top of that.

Heavy asterisk (u2731) in Android 2.x

I need Heavy asterisk (u2731) character in my app.
For android 3 and later I used the the following in my TextView:
android:text="\u2731"
and it works fine. But in android 2.x I see a rectangle instead of asterisk. I think that the specific Unicode character is missing in default fonts of Android 2.x .
So what can I do to see this character in Android 2.x? May be I need to load a custom font?
Which font contains this character?
As far as I know, Android 3.0 uses the Roboto font.
You can easily find it for free as a ttf font you might want to store in your assets folder.
Here is the reference and downlad site
[EDIT]
A workaround could be something like this:
String str = "your string containing fat asterisks (**)";
str = str.replace("**", "<b>*</b>");
myTextView.setText(Html.fromHtml(str));
It will make all the ** occurrences become a BOLD *

Android custom font not mapping properly

I have to implement Nepali Font on my application and for that I have used unicode font named DroidSansDevanagari-Regular.ttf.The reason I have used this font is that on my Rooted Galaxy S2 I900,I have installed Resurrection Remix 3.06 JB(AOKP) which renders Nepali Font correctly. And under system/fonts folder I have found this DroidSansDevanagari-Regular.ttf font,which is responsible for displaying Nepali Font.
Further I have used the correct way of using custom font
Typeface font =
Typeface.createFromAsset(context.getAssets(),
"fonts/DroidSansDevanagari- Regular.ttf");
someTextView.setTypeface(font);
And though my application displays the Nepali Font it doesn't correctly maps the font.Using same font I get correct mapping on Rooted Galaxy S2 phone,but I can't get correct mapping on other phones. Let me illustrate this by picture
Correct Mapping
InCorrect Mapping
So,my question is how to map the font in correct manner as done by my Rooted Galaxy S2 phone.For that do I have to look upon AOKP project and look upon EditText or Typeface classes.Please provide me guidance on how to correctly map the fonts on each and every device
Thanks in advance
For correct font mapping ,indic text renderer is the best solution I found so far.But before implementing this library,please look upon the solution explained on this issue in order to render fonts with long texts and without any line spacing in between words

CSV file containing phonetic letters trying to encode with UTF-8 in Android/Java

I have an Android- as well as iPhone-Version of my App. In iOS I can tell the CSV-Parser to encode the string with UTF-8. Apparently this is also possible in Android when I use the InputStreamReader when I open the CSV file.
isr = new InputStreamReader(getAssets().open(
"english.csv"), "UTF-8");
Also when I check the encoding
System.out.println(isr.getEncoding());
it returns UTF8.
The weird thing now is, that some phonetic words!! are shown completely correct, whereas most of them show phonetic words containing square symbols. Although the exact same letters are shown correctly in other words.
Ok guys,
apparently it only works with applying another font. Because the encoding really works. Only Android standard fonts have their problem displaying phonetic letters.
I followed this guy's solution:
I don't use unicode characters in my android-textview.How can I do this?
and used another font called Constructium. Just have to import it into your assets folder and use it either through the XML Layout file or directly in your code, as this guy has done it:
How to change the font on the TextView?

Customize Android Fonts

Now, I'm developing an android application, which needs to show some special characters. I need this font "Arial Unicode MS" to show the characters correctly. And I add the following code in my main activity:
EditText editText = (EditText) findViewById(R.id.flipped_window);
Typeface font = Typeface.createFromAsset(getAssets(),"ARIALUNI.TTF");
editText.setTypeface(font);
It does work. However, the size of this font file is too big, it's 22,731 kb.
Is there better solution for this problem? Thanks.
Your real problem is redistributing a copyrighted font. :-)
As Craig mentioned, you're illegally redistributing a copyrighted font.
My best guess would be to first look at all the glyphs available in Droid Sans; in my experience, it should be good enough unless you're looking to use it for formatting.
If you can't do that, create the symbols you need as PNG or GIF images and insert them inline. (GIFs will be substantially smaller for black & white).
buddy, you can decrease font size with Font creator software with elimination unused characters in font. you can decrease it to 50,60kb also :-)
password download link : www.downloadsoftware.ir

Categories

Resources