本文介绍了如何在Android中为TextView设置字体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我做了很多尝试来为我的应用程序中的TextView设置字体.但是似乎没有办法在android中设置字体.我想通过xml为我的所有TextView设置Arial字体.我将Arial.ttf添加到了仍然无法在xml中设置样式的资产中.请找到我的出路.
I tried a lot to set font for the TextView in my app. But there is no way seems to set font in android. I want to set Arial font for all of my TextView through xml. I added Arial.ttf to my assets still unable to set style in xml. Please find me a way out.
推荐答案
AFAIK,您无法在xml中完成它,而必须在代码中完成:
AFAIK you can't do it in xml, you have to do it in code:
Typeface tf = Typeface.createFromAsset(getAssets(),
"fonts/Arial.otf");
TextView tv = (TextView) findViewById(R.id.CustomFontText);
tv.setTypeface(tf)
这篇关于如何在Android中为TextView设置字体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!