Android(安卓)ApiDemos示例解析(83):Graphics->Typefaces
16lz
2021-12-04
本例介绍如何在Android中使用自定义字体,Android支持TureType字体,和Windows 支持的TrueType字体格式相同。
可以在Windows\Fonts 目录下 查看字体,比如将 Edwardian 字体拷贝到本例的assest\fonts目录下:
Typefaces_第1张图片" src="https://img.it610.com/image/info5/9ae22faff4944beebc6d7285a3b0472a.jpg" width="450" height="401" style="border:1px solid black;">
修改一下本例代码:
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_第2张图片" src="https://img.it610.com/image/info5/337b1d114c4f4b419d7f5100f57979f0.jpg" width="329" height="490" style="border:1px solid black;">
更多相关文章
- 收藏各种技术源码
- Android(安卓)App常用图标尺寸规范
- 通过xml布局文件实现按钮改变焦点设置背景图片
- android:inputType 属性及其支持的取值
- Android(安卓)UI系列-----ImageView的scaleType属性
- Android(安卓)是什么
- Android(安卓)开机动画
- android的selector的用法
- golang开发android应用(二) - go语言生成android动态库