如何在Android中为TextView设置字体?

10 浏览
0 Comments

如何在Android中为TextView设置字体?

可能是重复问题:

如何在Android上更改TextView的字体?

我尝试了很多方法来为我的应用程序中的TextView设置字体。但似乎没有办法在Android上设置字体。我想通过xml为所有的TextView设置Arial字体。我将Arial.ttf添加到我的资产中,但仍无法在xml中设置样式。请帮我找到一种解决方法。

0
0 Comments

在Android中设置TextView的字体需要在代码中进行,而不能在xml中进行。以下是一种解决方法:

Typeface tf = Typeface.createFromAsset(getAssets(),
"fonts/Arial.otf");
TextView tv = (TextView) findViewById(R.id.CustomFontText);
tv.setTypeface(tf)

0