android textview adapting device的字体

时间:2011-12-04 15:48:06

标签: android fonts textview

我的应用程序中有一些textview 并且所有这些似乎都适应了设备的文本字体。 我怎么能覆盖这个? 我希望我的所有文本视图都具体 字体与什么没有任何关系 设备的字体是

感谢

1 个答案:

答案 0 :(得分:1)

如果通过“特定字体”表示您将与应用捆绑在一起,请使用setTypeface()上的TextView将其与您创建的Typeface对象相关联你的字体:

TextView tv=(TextView)findViewById(R.id.custom);
Typeface face=Typeface.createFromAsset(getAssets(),
                                        "fonts/HandmadeTypewriter.ttf");

tv.setTypeface(face);

File font=new File(Environment.getExternalStorageDirectory(),
                   "MgOpenCosmeticaBold.ttf");

if (font.exists()) {
  tv=(TextView)findViewById(R.id.file);
  face=Typeface.createFromFile(font);

  tv.setTypeface(face);
}
else {
  findViewById(R.id.filerow).setVisibility(View.GONE);
}

(来自this sample project

请仅提供正确许可的字体,并请记住字体需要有足够的字形来涵盖您打算支持的所有语言。