我已经找到了几篇关于这个主题的帖子,但是所有这些主题要么在TextView
对象上使用setTypeFace()
方法设置字体,要么创建一个自定义类将字体设置为Roboto
和extends
TextView
。据我所知,API-Level 11(?)或者,我们可以将TypeFace设置为xml属性,等等。如下所示:
<TextView
android:id="@+id/profileHeader"
android:layout_width="100dp"
android:layout_height="100dp"
android:typeface="roboto"
android:text="Hello, world">
</TextView>
这样做的正确方法是什么?如果应用程序在低于API级别11(?)的设备上运行,是否可能出现回退?类似于:
android:typeface="roboto|monospace|serif"
发布于 2013-09-28 02:35:41
看一看RobotoTextView项目。适用于Android1.5,您可以使用XML属性设置字体。它还包括其他视图,如RobotoButton、RobotoCheckbox等。
发布于 2013-05-13 18:43:43
我没有看到可以将外部字体定义为xml属性的方法。您应该将字体存储在资源中,并调用:
tv.setTypeface( Typeface.createFromAsset( context.getAssets(), roboto.ttf ) );
发布于 2013-08-02 20:57:22
您不能直接从这样的资源设置字体,您必须在onCreate中执行以下操作。这将使同样的事情成为你想做的。
TextView tvTextView = (TextView) findViewById(R.id.textView1);
Typeface typeface = Typeface.createFromAsset(getAssets(),"Roboto.ttf");
tvTextView.setTypeface(typeface);
希望对你有帮助。:d
https://stackoverflow.com/questions/15733341
复制相似问题