Does Android support Windows fonts? and how to write Unicode text into a textview?

陌路散爱 提交于 2019-12-12 05:47:27

问题


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


回答1:


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



回答2:


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;
}


来源:https://stackoverflow.com/questions/36106570/does-android-support-windows-fonts-and-how-to-write-unicode-text-into-a-textvie

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!