使用 Android 5 或更高的个性化字体 - XML
Personalized font using Android 5 or higher - XML
我正在按照这个tutorial更改Xamarin.Android中应用程序的字体,它只是将.ttf
文件添加到项目中,然后引用TextView / EditText
你想在 XML
中使用它的地方,像这样:
android:fontFamily="@font/sourcerfont"
我遇到的问题是它只适用于虚拟设备,不适用于物理设备。
我重新阅读了文档(教程)并发现这部分引起了我的注意,并且我的印象是错误可能存在,因为我的物理设备有 API 23 - Android 6.0.1
;虚拟的有 Android 9.0
:
This feature is also supported on devices till Android 4.1 by using
Support Library 26 or more.
你能告诉我我做错了什么吗?
我认为您不能只在 Android 版本早于 8 的应用程序上使用自定义字体。
在所有设备上对我有用的唯一方法是这个,但它对于大型应用程序来说非常乏味:
TextView Lbl = FindViewById <TextView> (Resource.Id.Lbl34);
tf = Typeface.CreateFromAsset (Android.App.Application.Context.Assets, "quicks.ttf");
Lbl.SetTypeface (tf, TypefaceStyle.Normal);
I reread the documentation (the tutorial) and found this part that caught my attention, and I get the impression that the error could be there since my physical device has API 23 - Android 6.0.1; and the virtual one has Android 9.0
我下载 Karantina 字体系列,然后在 Resources 文件夹下创建一个名为 font 的文件夹。将字体文件放入其中, build action 设置为 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 虚拟 8.1(API27)、Android 物理设备 8.1(API27) 和 Android 物理设备 6.0(API23) 上测试我的代码,一切正常,有没问题。
我正在按照这个tutorial更改Xamarin.Android中应用程序的字体,它只是将.ttf
文件添加到项目中,然后引用TextView / EditText
你想在 XML
中使用它的地方,像这样:
android:fontFamily="@font/sourcerfont"
我遇到的问题是它只适用于虚拟设备,不适用于物理设备。
我重新阅读了文档(教程)并发现这部分引起了我的注意,并且我的印象是错误可能存在,因为我的物理设备有 API 23 - Android 6.0.1
;虚拟的有 Android 9.0
:
This feature is also supported on devices till Android 4.1 by using Support Library 26 or more.
你能告诉我我做错了什么吗?
我认为您不能只在 Android 版本早于 8 的应用程序上使用自定义字体。
在所有设备上对我有用的唯一方法是这个,但它对于大型应用程序来说非常乏味:
TextView Lbl = FindViewById <TextView> (Resource.Id.Lbl34);
tf = Typeface.CreateFromAsset (Android.App.Application.Context.Assets, "quicks.ttf");
Lbl.SetTypeface (tf, TypefaceStyle.Normal);
I reread the documentation (the tutorial) and found this part that caught my attention, and I get the impression that the error could be there since my physical device has API 23 - Android 6.0.1; and the virtual one has Android 9.0
我下载 Karantina 字体系列,然后在 Resources 文件夹下创建一个名为 font 的文件夹。将字体文件放入其中, build action 设置为 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 虚拟 8.1(API27)、Android 物理设备 8.1(API27) 和 Android 物理设备 6.0(API23) 上测试我的代码,一切正常,有没问题。