我做了下面。我得到的是基本字体,而不是我的自定义符号字体。
有任何想法吗?
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);
我的字体是assets/fonts/myFont.TTF
不是所有的字体支持Android。它只是默默地失败。
行动的一个当然是找到那绝对处理自定义字体的应用程序 - 如this sample app of mine - 作为实验的基础。您可以运行的应用程序,以确认其字体出现,然后替换那些与您的字体之一。如果这样的作品,然后有东西在你加载在字体的方式搞砸了(虽然我不知道什么或如何)。如果字体无法在我的示例应用程序,其中附带该应用程序不工作的字体,问题就出在字体工作。
不幸的是,我不知道是什么让一个字体工作或不工作。你可以尝试在字体编辑器中打开的字体,使得微小的变化(例如,删除一些你知道你将不需要字形),保存它回来了,看到修订后的字体作品。如果确实如此,这意味着,但是字体保存原来有什么事情,Android不喜欢,但你的字体编辑器可以生成的Android友好的字体。
你好,我有这方面你可以尝试以这种方式使用字体的解决方案...我有我的项目实现了这个...
脚步:
EditText
或按钮文本例如 :
public class ButtonHelveticaBold extends Button {
Context ButtonFontContext;
public ButtonHelveticaBold(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
ButtonFontContext = context;
}
public ButtonHelveticaBold(Context context, AttributeSet attrs) {
super(context, attrs);
ButtonFontContext = context;
}
public ButtonHelveticaBold(Context context) {
super(context);
ButtonFontContext = context;
}
@Override
public void setTypeface(Typeface tf, int style) {
Typeface typeFaceHelvetica;
if (style == Typeface.BOLD) {
typeFaceHelvetica = Typeface.createFromAsset(getContext().getAssets(), "fonts/helvetica_bold_neue.ttf");
} else {
typeFaceHelvetica = Typeface.createFromAsset(getContext().getAssets(), "fonts/helvetica_neue_regular.ttf");
}
super.setTypeface(typeFaceHelvetica);
}
}
3:在XML像这样使用:
<com.fontUtils.fonts.ButtonHelveticaBold
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>