在android系统中,自带的只有三种字体---"sans","serif"和"monospace",你只要在xml文件中的
android:typeface
属性使用它们:
<TableLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="fill_parent"android:stretchColumns="1"><TableRow><TextViewandroid:text="sans:"android:layout_marginRight="4px"android:textSize="20sp"/><TextViewandroid:id="@+id/sans"android:text="Hello, world!"android:typeface="sans"android:textSize="20sp"/></TableRow><TableRow><TextViewandroid:text="serif:"android:layout_marginRight="4px"android:textSize="20sp"/><TextViewandroid:id="@+id/serif"android:text="Hello, world!"android:typeface="serif"android:textSize="20sp"/></TableRow><TableRow><TextViewandroid:text="monospace:"android:layout_marginRight="4px"android:textSize="20sp"/><TextViewandroid:id="@+id/monospace"android:text="Hello, world!"android:typeface="monospace"android:textSize="20sp"/></TableRow><TableRow><TextViewandroid:text="Custom:"android:layout_marginRight="4px"android:textSize="20sp"/><TextViewandroid:id="@+id/custom"android:text="Hello, world!"android:textSize="20sp"/></TableRow></TableLayout>

有时候,系统自带的字体并不能满足我们特殊的需求,这时候就需要引用其他的字体了,可以把下载的字体文件放在assets目录下.自定义字体文件不能使用xml代码读取而应该使用java代码:
public class Test extends Activity {@Overridepublic void onCreate(Bundle icicle) {super.onCreate(icicle);setContentView(R.layout.main);TextView tv=(TextView)findViewById(R.id.custom);Typeface face=Typeface.createFromAsset(getAssets(),"fonts/HandmadeTypewriter.ttf");//也可以使用其他的静态方法获取tv.setTypeface(face);}}

这个ttf文件在http://moorstation.org/typoasis/designers/klein07/text01/handmade.htm。
注意:如果你下载的字体Android不支持,那么系统会使用默认字体"sans"。由于应用自定义字体需要额外空间,所以一般不是都需要自定义字体的.

更多相关文章

  1. android webView与js交互
  2. android读取功能
  3. Android(安卓)笔记一:线性布局
  4. Android中接口的使用及类使用
  5. Android使用VideoView全屏播放视频拉伸变形解决办法
  6. android linux 基础知识总结
  7. Android应用开发相关下载资源
  8. Android布局图标中心化
  9. android 开发:使用SwipeRefreshLayout实现下拉刷新

随机推荐

  1. android singleTask使用情况,场景分析
  2. Android(安卓)Audio代码分析7 - stream t
  3. Andriod(三):配置文件build.gradle与Android
  4. Android(安卓)中Preferences的使用!
  5. android入门学习的网上资料总结
  6. android4.4修改低电压提醒
  7. Android(安卓)C++中调用java
  8. 关于Android中的四大组件(Activity)
  9. android 定位到输入的地址
  10. Android(安卓)View系统源码分析(十)—— Vi