使用自定义字体时出现问题 - “无法制作原生字体”
我正在尝试使用在互联网上找到的字体,但问题是我得到的 FC 带有“无法制作原生字体”。
这是我的 ListVIew 的 getView 中的代码:
holder.tv_SuraName =(TextView)convertView.findViewById(R.id.Start_Name);
holder.tv_SuraName.setTypeface(Typeface.createFromAsset(mContext.getAssets(), "suralist_font.ttf"));
谁能告诉我为什么可以使用自定义 rom?您可以在此处获取它..该文件是.ttf
I'm trying to use a font I found on the internet, but the problem is that I get an FC with "native typeface cannot be made".
Here is the code in the getView of my ListVIew:
holder.tv_SuraName =(TextView)convertView.findViewById(R.id.Start_Name);
holder.tv_SuraName.setTypeface(Typeface.createFromAsset(mContext.getAssets(), "suralist_font.ttf"));
Can anyone tell me why can I use the custom rom? You can get it HERE .. the file is .ttf
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(16)
我的问题是资产文件夹的位置不正确。
使用 Android Studio 时,资产文件夹应位于源集内,例如
发现于这个答案
My problem was incorrect placement of the assets folder.
When using Android Studio the assets folder should be inside of the source sets e.g.
Found in this answer
字体文件已损坏或由于某种原因不受支持。您可以将其放在 SD 卡上并从文件中加载,以确保您的资产不会出现问题。
The font file is either corrupt or unsupported for some reason. You can drop it on the SD card and load it from file, to make sure it's not a problem with your assets.
基本上有 4 种情况可能会导致这种情况:
There are basically 4 things that can cause this:
仔细检查扩展名是否大写,即。 suralist_font.TTF
字体通常看起来是这样的,但它可能会被忽视。
Double check the extension isn't in caps, ie. suralist_font.TTF
Fonts often come seem to come that way and it might be overlooked.
我遇到了同样的问题,我在 asset>fonts>whatever.ttf 中创建了我的问题,但遇到了相同的错误。我添加了字体扩展(fonts/whatever.ttf),它解决了每种情况下的问题。
I had this same problem, I created mine in assets>fonts>whatever.ttf and was getting the same error. I added the fonts extension (fonts/whatever.ttf) and it fixed the problem in every case.
相当旧的线程,但我想添加另一个可能发生这种情况的原因:您必须在调用字体之前设置内容视图。请参阅下面的示例
是否不起作用:
起作用!
Rather old thread, but I want to add one more reason this can happen: You have to set the content view before calling typeface. See example below
Does not work:
Does work!
我正在使用 android studio,在我的例子中,问题出在资产文件夹的路径上,在 Eclipse 中资产文件夹的路径是 res/assets/ 但在 Android Studio 中它是 src/main/assets/
所以,我只是将我的字体文件移动到这个路径,最终问题解决了。
I am using android studio, in my case problem was with the path of assets folder, in Eclipse path for assets folder is res/assets/ but in Android Studio its src/main/assets/
So, i just move my font file to this path and finally problem solved.
要么您的字体文件已损坏,要么您在调用文件名时犯了一些拼写错误。我遇到了同样的问题,这是因为资产文件夹中指定的文件名是
并在 java 文件中声明时,我将其拼写为:
如果您的 .ttf 文件位于 asset 文件夹中,则使用:
否则如果它位于 fonts 文件夹中,则使用:
希望它有帮助!
Either your font file is corrupt else you making some mistake in spelling while calling your file name. I had same issue, it was because file name specified in asset folder was
and while declaring in java file, i have been spelling it as:
If your .ttf files are in asset folder,then use:
Else if it is in fonts folder, then use:
Hope it helps!
希望这将有助于
Typeface.createFromAsset 泄漏资源流:http://code. google.com/p/android/issues/detail?id=9904
Hope this will help
Typeface.createFromAsset leaks asset stream: http://code.google.com/p/android/issues/detail?id=9904
正如 CommonsWare 在这个答案中所述
不管怎样,试试这个:
As CommonsWare states in this answer
Anyway try this one:
我对来自Windows 的comic sans ms 的COMIC.TTF 也有同样的问题。
由于我放置在 asset/fonts 文件夹中的原始文件如上面拼写的那样是大写的,因此我必须完全以大写形式输入它。
Typeface.createFromAsset(getAssets(), "fonts/COMIC.TTF");
事实证明问题是由小写引起的:
Typeface.createFromAsset(getAssets(), "fonts/comic.ttf");
I had the same problem with COMIC.TTF from comic sans ms of Windows.
Since the original file I placed in assets/fonts folder was in uppercase as spelt above, I had to type it exactly in uppercase.
Typeface.createFromAsset(getAssets(), "fonts/COMIC.TTF");
it turns out the problem was caused by the lower case:
Typeface.createFromAsset(getAssets(), "fonts/comic.ttf");
请注意,这是由于文件损坏或您将该文件放置在错误的文件夹中造成的。
根据Android文档此处
因此,您的文件夹结构应该是 yourmodule/main/assets (例如 a***pp/main/assets*** )
Please note that this is due to either a corrupt file or you have placed the file in the wrong folder.
According to Android documentation here
Therefore your folder structure should be yourmodule/main/assets (e.g. a***pp/main/assets*** )
对我有用的是首先将我的字体名称更改为仅小写和下划线:从 Amatic-Sc.ttf 到 amatic_sc.ttf。
然后在 set.TypeFace 方法中将 assets/fonts/amatic_sc.ttf 更改为 fonts/amatic_sc.ttf。
What worked for me was first changing my font name to only lower case and underscore: from Amatic-Sc.ttf to amatic_sc.ttf.
Then in the set.TypeFace method change assets/fonts/amatic_sc.ttf to just fonts/amatic_sc.ttf.
我一直在 Android Studio 中调试这个错误。将字体添加到资产目录后清理并重建项目为我解决了这个问题。
I've been debugging forever on this error in Android Studio. Clean and rebuilding the project after adding the fonts to the assets directory fixed the issue for me.
刚刚做了一个
构建 --> clean
并开始渲染。Just did a
build --> clean
and it started rendering .我在 Android 4.0.3-4.0.4 上遇到了同样的问题(在模拟器 IceCreamSandwich mips 4.0.3 上可 100% 重现)。
问题是我拥有的 TTF 字体不正确,尽管几乎所有 Android 版本都能够加载这些 TTF 字体。所以我使用了 https://cloudconvert.com/woff-to-ttf (因为我有woff 文件)来制作新的 TTF 字体,这解决了我的问题。
I had same issue which happened on Android 4.0.3-4.0.4 (100% reproducible on emulator IceCreamSandwich mips 4.0.3).
The problem was that TTF fonts, that I had, were not correct, despite almost all Android versions were able to load those TTF font. So I used https://cloudconvert.com/woff-to-ttf (since I had woff files as well) to make new TTF fonts, which solved my problem.