转自http://www.cnblogs.com/Gaojiecai/archive/2012/05/06/2485541.html
本类的常量静态定义
字体类型(typeface)名称
Typeface DEFAULT//<span style="font-size:10.5pt"><span style="font-size:10.5pt">默认字体</span></span>
Typeface DEFAULT_BOLD//<span style="font-size:10.5pt"><span style="font-size:10.5pt">默认粗体</span></span>
Typeface MONOSPACE//<span style="font-size:10.5pt">单间隔字体</span>
Typeface SANS_SERIF//<span style="font-size:10.5pt">无衬线字体</span>
Typeface SERIF//<span style="font-size:10.5pt">衬线字体</span>
字体风格(style)名称
int BOLD//<span style="font-size:10.5pt">粗体</span>
int BOLD_ITALIC//<span style="font-size:10.5pt">粗斜体</span>
int ITALIC//<span style="font-size:10.5pt">斜体</span>
int NORMAL//<span style="font-size:10.5pt">普通字体</span>
设置TextView的字体可以通过TextView中的setTypeface方法来指定一个Typeface对象 因为Android的字体类 比较简单,我们列出所有成员方法:
//静态方法,参数一为字体类型这里是Typeface的静态定义,如宋体,参数二风格,如粗体,斜体
static Typeface create(Typeface family, int style)
//静态方法,参数一为字体名的字符串,参数二为风格同上,这里我们推荐使用上面的方法。
static Typeface create(String familyName, int style)
//静态方法,参数一为AssetManager对象,主要用于从APK的assets文件夹中取出字体,参数二为相对于Android工程下的assets文件夹中的外挂字体文件的路径。
//静态方法,从文件系统构造一个字体,这里参数可以是sdcard中的某个字体文件
static Typeface createFromFile(File path)
//静态方法,从指定路径中构造字体
static Typeface createFromFile(String path)
//静态方法,返回默认的字体风格
static Typeface defaultFromStyle(int style)
//获取当前字体风格
int getStyle()
//判断当前是否为粗体
final boolean isBold()
//判断当前风格是否为斜体
final boolean isItalic()
例程:
<!-- 使用默认的sans字体-->
<TextView
android:id="@+id/sans"
android:text="Hello,World"
android:typeface="sans"
android:textSize="20sp">
</TextView>
<!-- 使用默认的serifs字体-->
<TextView
android:id="@+id/serif"
android:text="Hello,World"
android:typeface="serif"
android:textSize="20sp">
</TextView>
<!-- 使用默认的monospace字体-->
<TextView
android:id="@+id/monospace"
android:text="Hello,World"
android:typeface="monospace"
android:textSize="20sp">
</TextView>
//得到TextView控件对象
TextView textView = (TextView)findViewById(R.id.custom);
//将字体文件保存在assets/fonts/目录下,创建Typeface对象
Typeface typeFace = Typeface.createFromAsset(getAssets(), "fonts/HandmadeTypewriter.ttf");
//应用字体
textView.setTypeface(typeFace);