Android Galxy Tab 运行时异常:无法制作原生字体?
我正在尝试使用自定义字体 它可以在模拟器上运行,没有任何问题。
但在 Smsung Galaxy Tab 上抛出以下错误: 无法制作原生字体
这是我的代码:
public static Typeface typeface;
// -----define typeface
typeface = Typeface.createFromAsset(getAssets(), "fonts/Verdana.TTf");
Typeface.class.getField("DEFAULT").setAccessible(true);
---------------------
lblBrandCategory1.setTypeface(GuestActivity.typeface, 4);
anyone knows the solution???
I'm trying to use custom fonts
It works on emulator with no isses.
But on Smsung Galaxy Tab is throwing following error:
native typeface cannot be made
Here is my code:
public static Typeface typeface;
// -----define typeface
typeface = Typeface.createFromAsset(getAssets(), "fonts/Verdana.TTf");
Typeface.class.getField("DEFAULT").setAccessible(true);
---------------------
lblBrandCategory1.setTypeface(GuestActivity.typeface, 4);
anyone knows the solution???
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我的这个(在 Galaxy Tab 上)几乎和你正在做的一样。结果对我来说是一个区分大小写的问题,例如文件名全部小写,而我在java代码中将.ttf文件名大写。
因此,这可能意味着只要找不到 ttf,您就会收到此错误(因此请检查您的路径是否良好)。
I had this (on a Galaxy Tab as it happens) doing pretty much exactly what you're doing. Turned out to be a case-sensitivity issue for me, e.g. filename was all lowercase and I capitalized the .ttf filename in the java code.
So presumably that means that you get this error whenever the ttf can't be found (so check your path is good as well).
我遇到了同样的问题,我不认为它依赖于设备。
我通过确保以下几点解决了这个问题:
如果您有多个项目,请确保您的字体文件存储在主项目的资产文件夹中 - 而不是依赖项目。< /p>
为了安全起见,请将字体重命名为全部小写,并在代码中引用它。
FontUtils.setDefaultFont(this, "DEFAULT", "fonts/arimo-regular.ttf");
这是一个用于覆盖整个应用程序默认字体的类。
I had the same issue, I don't believe it's device dependent.
I solved it by making sure of the following:
If you have more than one project, make sure your font file is stored in the assets folder of your main project - not a dependency project.
for safety, rename your font to all lowercase and reference it as such in your code.
FontUtils.setDefaultFont(this, "DEFAULT", "fonts/arimo-regular.ttf");
Here is a class to override the default font for my entire application.