繁体   English   中英

Java.Lang.RuntimeException:找不到字体资产

[英]Java.Lang.RuntimeException: Font asset not found

如标题所示,字体文件似乎找不到。 我引用错误:

未处理的异常:

Java.Lang.RuntimeException:找不到字体资产fontawesome-webfont.ttf“

代码是:

public class MainActivity : Activity
{
    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);

        SetContentView(Resource.Layout.Main);

        AssetManager assets = this.Assets;
        Typeface font = Typeface.CreateFromAsset(assets, "fontawesome-webfont.ttf");

        // Set our view from the "main" layout resource
        Button button = (Button)FindViewById(Resource.Id.btnIniciarSesion);
        button.SetTypeface(font, TypefaceStyle.Normal);

        // Get our button from the layout resource,
        // and attach an event to it
    }
}

字体文件位于资产文件夹中,如下图所示:

资产文件夹中的字体文件

我可以尝试什么?

尝试这个,

Typeface font = Typeface.createFromAsset(getContext().getAssets(),  "fontawesome-webfont.ttf");

我删除并再次创建了解决方案,问题“神奇地”消失了。

您应该在“ fontawesome-webfont.ttf”文件属性中设置-> build Action,然后选择AndroidAsset

试试这个指令对我有用

Typeface oswaldFont = Typeface.CreateFromAsset(Assets, "Oswald.ttf");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM