Canvas drawText(font)import Times字体?

问题描述 投票:0回答:1

我正在尝试将Times用作Canvas元素的drawText()方法的字体。但是尚未找到解决方案。

可以使用以下代码来设置'sans-serif'或'casual'之类的字体:

paint.setTypeface(Typeface.create("casual",Typeface.NORMAL));

但是尝试使用Times或Arial等无效。我必须先自己导入这些字体吗?

如果您有解决方案,将不胜感激。预先谢谢!

android android-canvas android-typeface
1个回答
0
投票
来设置字体,例如'sans-serif'或'casual'。

首先,您需要在'main'文件夹下创建一个'assets'文件夹,并在其中放入.ttf文件之类的字体文件。

assets folder path

这是休闲字体下载链接

https://befonts.com/casual-font.html

我希望这是您想要的答案。谢谢

示例)

Typeface mTfRegular;
Typeface mTfLight;

mTfRegular = Typeface.createFromAsset(getContext().getAssets(), "OpenSans-Regular.ttf");
mTfLight = Typeface.createFromAsset(getContext().getAssets(), "OpenSans-Light.ttf");
© www.soinside.com 2019 - 2024. All rights reserved.