android将自定义字体设置为油漆 [英] android set custom font to a paint

查看:37
本文介绍了android将自定义字体设置为油漆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在油漆上绘制文本.如何使用自定义字体(ex Helvetica)和粗体绘制它?我更愿意使用系统字体而不是从资产中创建它.谢谢.

I want to draw a text to a paint. How to draw it with a custom font (ex Helvetica ) and bold also? I would preffer to use a system font and not create it from assets. Thanks.

推荐答案

如果自定义字体"是指您作为资产提供的字体,则以下代码应该有效:

If by "custom font" you mean a font that you are supplying as an asset, the following code should work:

Typeface plain = Typeface.createFromAsset(assetManager, pathToFont); 
Typeface bold = Typeface.create(plain, Typeface.DEFAULT_BOLD)
Paint paint = new Paint();
paint.setTypeface(bold);
canvas.drawText("Sample text in bold",0,0,paint);

这篇关于android将自定义字体设置为油漆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆