自定义字体不适用于Android [英] Custom Font not working on Android

查看:191
本文介绍了自定义字体不适用于Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做下面的。所有我得到的是基本的字体,而不是我自定义的符号字体。



有什么想法?

  Paint pnt = new Paint(); 
// SymbolNo是38.返回字符串&这在正常字体中是正确的。
字符串symbolText = Character.toString((char)SymbolNo);

//应该采用符号字体,然后画符号来屏蔽。但我只看到&
Typeface tf = Typeface.createFromAsset(m_context.getAssets(),fonts / myFont.TTF);
pnt.setTypeface(tf);

m_canvas.drawText(symbolText,x,y,pnt);

我的字体位于 assets / fonts / myFont.TTF

解决方案

并非所有的字体都适用于Android。它只是默默地失败。

一个行动的方法是找到一个明确处理自定义字体的应用程序,例如这个示例应用程序 - 作为实验的基础。您可以运行该应用程序以确认其字体出现,然后用您的字体替换其中的一个。如果这样的话,那么在你装入字体的时候就会出现一些乱七八糟的东西(虽然我不知道是什么或者怎么样)。如果字体在我的示例应用程序中无法正常工作,那么与该应用程序一起提供的字体确实有效,问题在于字体。



不幸的是,我不知道什么使字体工作或不工作。您可以尝试在字体编辑器中打开字体,做一些小改动(例如,删除某些您不需要的字形),将其保存,然后查看修改过的字体是否正常工作。如果是这样的话,那意味着不过这个字体已经被保存了,但是Android不喜欢,但是你的字体编辑器可以生成友好的字体。

I am doing the below. All I get is the basic font, not my custom symbol font.

Any ideas?

     Paint pnt = new Paint();
    // SymbolNo is 38. Returns string "&" which is correct in normal font.
    String symbolText = Character.toString((char)SymbolNo); 

    // Should adopt a symbol font and draw symbol to screen instead. But I just see "&"
    Typeface tf = Typeface.createFromAsset(m_context.getAssets(), "fonts/myFont.TTF" ); 
    pnt.setTypeface(tf);

    m_canvas.drawText(symbolText,x, y, pnt);

my font is in assets/fonts/myFont.TTF

解决方案

Not every font works with Android. It just silently fails.

One course of action is to find an app that definitely handles a custom font -- such as this sample app of mine -- as a basis for experimentation. You can run that app to confirm that its fonts appear, then replace one of those with your font. If that works, then there is something messed up in the way you are loading in the font (though I have no idea what or how). If the font fails to work in my sample app, where the font that ships with that app does work, the problem lies in the font.

Unfortunately, I have no idea what makes a font work or not work. You could try opening the font in a font editor, making a minor change (e.g., deleting some glyph you know that you won't need), saving it back out, and seeing if the revised font works. If it does, that means that however the font was saved originally has something in it that Android does not like, but that your font editor can generate Android-friendly fonts.

这篇关于自定义字体不适用于Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆