C# Java.Lang.RuntimeException:找不到字体资源
正如标题所示,字体文件似乎找不到。 我引述错误: 未处理的异常: Java.Lang.RuntimeException:找不到字体资源 FontWebFont.ttf“ 代码是:C# Java.Lang.RuntimeException:找不到字体资源,c#,android,xamarin,fonts,assets,C#,Android,Xamarin,Fonts,Assets,正如标题所示,字体文件似乎找不到。 我引述错误: 未处理的异常: Java.Lang.RuntimeException:找不到字体资源 FontWebFont.ttf“ 代码是: public class MainActivity : Activity { protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource
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
}
}
字体文件位于assets文件夹中,如下图所示:
我能试试什么?试试这个
Typeface font = Typeface.createFromAsset(getContext().getAssets(), "fontawesome-webfont.ttf");
试试这个
Typeface font = Typeface.createFromAsset(getContext().getAssets(), "fontawesome-webfont.ttf");
我删除并再次创建了解决方案,问题“神奇”地消失了。我删除并再次创建了解决方案,问题“神奇”地消失了。您应该在“fontawesome-webfont.ttf”文件属性->构建操作中设置,然后选择AndroidAsset您应该在“fontawesome-webfont.ttf”中设置“文件属性->构建操作并选择AndroidAsset试试这条指令,它对我有用。”
Typeface oswaldFont = Typeface.CreateFromAsset(Assets, "Oswald.ttf");
试试这个指令,它对我有用
Typeface oswaldFont = Typeface.CreateFromAsset(Assets, "Oswald.ttf");
字体生成操作是否设置为AndroidAsset?另一个问题可能是,您键入字体的方式实际上可能不是所包含字体的名称。例如,我在Xamarin应用程序中使用Segoe字体,而名为font的UISegoe位于UISegoeRegular.ttf中。您可以通过在字体查看器(如@BrewMate)中打开字体来解决这个问题。我尝试了您的建议,但没有成功。默认情况下,字体生成操作位于AndroidAsset中。因此,我尝试使用字体名称,就像在字体查看器中显示(“FontAwesome”)一样,问题仍然存在。我在代码中这样做,它对我有效:
Typeface font=Typeface.CreateFromAsset(“segoUI”,“SegoeUIRegular.ttf”)代码>字体生成操作是否设置为AndroidAsset?另一个问题可能是,您键入字体的方式实际上可能不是所包含字体的名称。例如,我在Xamarin应用程序中使用Segoe字体,而名为font的UISegoe位于UISegoeRegular.ttf中。您可以通过在字体查看器(如@BrewMate)中打开字体来解决这个问题。我尝试了您的建议,但没有成功。默认情况下,字体生成操作位于AndroidAsset中。因此,我尝试使用字体名称,就像在字体查看器中显示(“FontAwesome”)一样,问题仍然存在。我在代码中这样做,它对我有效:Typeface font=Typeface.CreateFromAsset(“segoUI”,“SegoeUIRegular.ttf”)代码>“CS0103名称“getContext”在当前上下文中不存在”“CS0103名称“getContext”在当前上下文中不存在”