有没有办法在4.0设备上使用fontFamily?

时间:2013-04-25 15:28:10

标签: android android-layout

android:fontFamily已应用于设备>这意味着4.1具有此属性但不是4.0.4。例如。 所以我正在尝试使用

android:fontFamily="sans-serif-light"

获得全息字体。它在4.2中很酷但在4.0.4上没有,它显示了一些默认字体。

无论如何都要用xml设置它?或者我要按代码设置它吗?

1 个答案:

答案 0 :(得分:2)

最简单的方法是在代码上执行此操作!将字体放在资源文件夹中,在文本视图中创建并设置它:

TextView text = (TextView) findViewById(R.id.textview03);
Typeface tf = Typeface.createFromAsset(getAssets(), "Molot.otf");
text.setTypeface(tf);

可以在xml上执行此操作。这个想法要困难得多。您必须扩展TextView组件并在xml而不是典型的Android TextView上使用它。

请查看this answer,详细了解如何实现这一目标。