0

Is it possible to use Windows fonts (.ttf file) in Android applications?

I have some unicode-8 texts like this:

جۆرەه

and I want to put it into a textView,, I tried some other methods but they did not work. Now, I want to embed a font into the application to read the text correctly..

By the way, it is Kurdish Language..

Any help is appreciated

Kurdish Programmer
  • 403
  • 1
  • 4
  • 14
  • This is not "Unicode-8", this is invalid (because of spaces between the `` and the number) HTML entity encoding. It has nothing to do with fonts. If you want to display it in a textview, decode it back to a normal `string` first. – GSerg Mar 19 '16 at 20:14
  • @GSerg I put the spaces by myself,,, to let the text be shows as it appear on my app,, HTML automatically convert it to a readable text.. – Kurdish Programmer Mar 19 '16 at 20:20
  • @GSerg Would you please show me how to decode this test to a readable one?? – Kurdish Programmer Mar 19 '16 at 20:21
  • Possible duplicate of [Decode HTML entities in android](http://stackoverflow.com/q/2918920/11683) – GSerg Mar 19 '16 at 21:13

2 Answers2

3

Well, yes you can use .ttf files in Android Applications. Navigate to your Android project's src/main folder, make a new folder assets there and paste your .ttf file in it. You can place your font in the directory which supports your language. After that, you can use the font in an EditText like this:

// For Setting the typeface in the TextViews
    Typeface xyzTypeFace = Typeface.createFromAsset(getAssets(), "xyz.ttf");
    TextView taglineTextView = (TextView) findViewById(R.id.taglineTextView);
    taglineTextView.setTextSize(25);
    taglineTextView.setTypeface(xyzTypeFace);
gautamprajapati
  • 2,055
  • 5
  • 16
  • 31
  • Thanks brain for your answer,, I embedded the font as you said.. but the problem is still not solved and the text is not readable yet... is there any way to decode this?? as @GSerg mention something like this?? – Kurdish Programmer Mar 19 '16 at 20:52
  • I would suggest you to go through these links: http://stackoverflow.com/questions/6054826/display-all-unicode-chars-in-textview and http://stackoverflow.com/questions/11145681/how-to-convert-a-string-with-unicode-encoding-to-a-string-of-letters – gautamprajapati Mar 19 '16 at 20:55
1

Thank you guys for your answers,

Finally, I solved the problem by using the following method..

    public static String fixEncodingUnicode(String response) {
    String str = "";
    try {
        str = new String(response.getBytes("ISO-8859-1"), "UTF-8");
    } catch (UnsupportedEncodingException e) {

        e.printStackTrace();
    }

    String decodedStr = Html.fromHtml(str).toString();
    return  decodedStr;
}
Kurdish Programmer
  • 403
  • 1
  • 4
  • 14
  • Why are you encoding `response` to ISO-8859-1 and then decoding it as if it were UTF-8? Why not just pass `response` as-is directly to `Html.fromHtml()`? You start with a `String` and end up with a `String`, so just leave it as a `String` and don't mess around with byte encodings in between. If you are having a problem with encoding mismatches, that needs to be fixed at the source where it is being mismatched to begin with, not patched at a later time. – Remy Lebeau Mar 21 '16 at 23:17
  • You should give credit to brainbreaker's answer. Your question asked about how to use a `.ttf` file in Android, not how to decode an HTML-encoded string into Unicode characters for display. Two separate questions. brainbreaker answered the question that was asked. The HTML issue should have been asked separately. – Remy Lebeau Mar 21 '16 at 23:22
  • Thank you @RemyLebeau for the comments,, Yes, as you said I removed all the flags in json.encode() method in the source.. then I removed this method in my app and everythings going on well.. about the second comment,, I had a problem, I wanted to solve it. you are right that brain answered a part of the question but the problem still not solved.. by the way, I upvoted brain :) best wishes – Kurdish Programmer Mar 21 '16 at 23:30
  • StackOverflow is a Q&A site. The answer you posted may provide the solution that solved your underlying problem, but it does not do anything to answer the question that you actually asked ("*Is it possible to use Windows fonts (.ttf file) in Android applications?*"). Brainbreaker's answer does ("*Yes, using Typeface.createFromAsset()...*"), and should have been marked as the correct answer for this question. Give credit where credit is due, otherwise you should delete this question. Questions and Answers should be related to each other. – Remy Lebeau Mar 21 '16 at 23:38