Android字体

2015-10-19  本文已影响253人  陈大集

Android系统默认了三种字体
sans
serif
monospace

可以通过下面的方式设置字体

<!--  使用默认的sans字体-->        
<TextView    
  android:id="@+id/sans"                   
  android:text="Hello,World"                   
  android:typeface="sans"                   
  android:textSize="20sp" />

如果上面三种字体都不符合要求,可以通过

1.在assets/fonts/目录下添加字体文件,如*.ttf
2.在Java代码中进行设置

//得到TextView控件对象        

TextView textView =(TextView)findViewById(R.id.custom);

//将字体文件保存在assets/fonts/目录下,创建Typeface对象
Typeface typeFace =Typeface.createFromAsset(getAssets(),"fonts/HandmadeTypewriter.ttf");
//使用字体
textView.setTypeface(typeFace);
上一篇 下一篇

猜你喜欢

热点阅读