本例介绍如何在Android中使用自定义字体,Android支持TureType字体,和Windows 支持的TrueType字体格式相同。

可以在Windows\Fonts 目录下 查看字体,比如将 Edwardian 字体拷贝到本例的assest\fonts目录下:

修改一下本例代码:

private static class SampleView extends View {  private Paint    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);  private Typeface mFace;  private Typeface mFace1;    public SampleView(Context context) {  super(context);    mFace = Typeface.createFromAsset(getContext().getAssets(),  "fonts/samplefont.ttf");    mFace1 = Typeface.createFromAsset(getContext().getAssets(),  "fonts/edwardian.ttf");    mPaint.setTextSize(64);  }    @Override protected void onDraw(Canvas canvas) {  canvas.drawColor(Color.WHITE);    mPaint.setTypeface(null);  canvas.drawText("Default", 10, 100, mPaint);  mPaint.setTypeface(mFace);  canvas.drawText("Custom", 10, 200, mPaint);  mPaint.setTypeface(mFace1);  canvas.drawText("Edwardian", 10, 300, mPaint);  } }


Typefaces" class="aligncenter size-full wp-image-1645" width="329" title="20110606007" height="490">

更多相关文章

  1. android Dialog大小修改
  2. 从 Android(安卓)Sample ApiDemos 中学习 android.animation API
  3. android源码下载方式
  4. 修改android系统和watchdog的延时
  5. Android(安卓)屏幕设置
  6. android WebView 图片缩放功能小结
  7. android支持多行的radiogroup
  8. android.support.v7使用,出错处理
  9. Android修改字体样式

随机推荐

  1. Android中的Selector的用法
  2. Android窗口机制(二)Window,PhoneWindow,Deco
  3. Android的IPC机制
  4. [Android]android源码下载&Eclipse关联an
  5. 【android】EditText属性大全
  6. 随笔:Android不爱C++
  7. 【Android常用控件】EditText常用属性【
  8. Android短信的发送和广播接收者实现短信
  9. Android(安卓)面试题总结之Android(安卓)
  10. Android之Activity透明背景