当我以Debug模式构建和部署包含自定义字体的Xamarin.android应用程序时,一切正常。我可以在应用程序中看到自定义ttf字体。但是,当我以Release模式构建和部署相同的应用程序时,运行它时我会看到默认字体。是否需要添加某些必需权限才能使自定义字体在应用程序中可见?
以下是我在应用程序中使用字体的方式:
以下是我在应用程序中使用字体的方式:
Convert method in converter class:
protected override Typeface Convert(string fontName, Type targetType, object parameter, System.Globalization.CultureInfo culture) { try { if (!fontName.StartsWith(@"font/")) fontName = @"font/" + fontName; if (!fontName.EndsWith(".ttf")) fontName += ".ttf"; if (!_cache.ContainsKey(fontName)) { _cache[fontName] = Typeface.CreateFromAsset(Application.Context.Assets, fontName); } return _cache[fontName]; } catch (Exception e) { Android.Util.Log.Error("AndroidFont", e.ToString()); return Typeface.Default; } }
Item in AXML
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:local="http://schemas.android.com/apk/res-auto" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#ffffff" > <TextView android:layout_width="180dp" android:layout_height="wrap_content" android:textColor="#AAAAAA" local:MvxBind="Typeface StringToFont('Lato'), Converter=StringToFontConverter" /></LinearLayout>
Registering converter in Setup.cs
protected override void FillTargetFactories(IMvxTargetBindingFactoryRegistry registry) { registry.RegisterFactory(new MvxCustomBindingFactory<View>("StringToFont", view => new BackgroundBinding(view))); }
TTF字体位于Assets / fonts目录中。我使用的是Visual Studio Community 2015(C#)。
在Debug模式下一切正常,但当我切换到Release模式时,我的字体(Lato)被默认的Android字体替换了。为什么?