C# 使用Android 5或更高版本的个性化字体-XML

C# 使用Android 5或更高版本的个性化字体-XML,c#,android,xml,xamarin,xamarin.android,C#,Android,Xml,Xamarin,Xamarin.android,下面我将更改Xamarin.Android中应用程序的字体,它只是将.ttf文件添加到项目中,然后在XML中引用文本视图/EditText,如下所示: android:fontFamily="@font/sourcerfont" 我遇到的问题是,它只适用于虚拟设备,而不适用于物理设备 我重新阅读了文档(教程),发现这一部分引起了我的注意,我得到的印象是错误可能就在那里,因为我的物理设备具有API 23-Android 6.0.1;而虚拟机有安卓9.0: 在Android 4

下面我将更改Xamarin.Android中应用程序的字体,它只是将
.ttf
文件添加到项目中,然后在
XML
中引用
文本视图/EditText
,如下所示:

android:fontFamily="@font/sourcerfont"
我遇到的问题是,它只适用于虚拟设备,而不适用于物理设备

我重新阅读了文档(教程),发现这一部分引起了我的注意,我得到的印象是错误可能就在那里,因为我的物理设备具有API 23-Android 6.0.1;而虚拟机有安卓9.0:

在Android 4.1之前,通过使用 支持库26或更多

你能告诉我我做错了什么吗

我不认为你只能在版本早于8的Android应用程序上使用自定义字体

对我来说,在所有设备上都有效的唯一方法是这样,但对于大型应用程序来说,这是非常乏味的:

TextView Lbl = FindViewById <TextView> (Resource.Id.Lbl34);
            tf = Typeface.CreateFromAsset (Android.App.Application.Context.Assets, "quicks.ttf");
            Lbl.SetTypeface (tf, TypefaceStyle.Normal);
TextView Lbl=findviewbyd(Resource.Id.Lbl34);
tf=Typeface.CreateFromAsset(Android.App.Application.Context.Assets,“quick.ttf”);
Lbl.SetTypeface(tf,typestyle.Normal);
我重新阅读了文档(教程),发现这一部分引起了我的注意,我得到的印象是错误可能在那里,因为我的物理设备有API 23-Android 6.0.1;而虚拟机有安卓9.0

我下载字体系列,然后在资源文件夹下创建一个名为字体的文件夹。将字体文件放入其中,构建操作设置为AndroidResource,请参见以下屏幕截图:

我使用这种自定义字体:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" android:orientation="vertical">
<TextView
   android:text="My text content"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
 android:fontFamily="@font/karantinaregular" />

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="karantina Bold" 
    android:fontFamily="@font/karantinabold"/>
 <TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="karantina Light" 
    android:fontFamily="@font/karantinalight"/>


我在Android virtual 8.1(API27)、Android physical device 8.1(API27)和Android physical device 6.0(API23)上测试了我的代码,它们都可以正常工作。

谢谢。我做了所有这些,但仍然没有在我的Android 6设备上显示。刚刚重新检查过。你在那个特殊的设备上复制了什么特别的细节?确实是安卓6设备吗?@Kenny.Ali安卓6设备没有特殊设置,您可以尝试在其他物理设备上构建吗?