我正在开发一个xamarin Android应用程序,需要在应用程序中使用FontAwesome图标。但不知道如何使用它。网上有很多文章,但我不清楚。
如何在 Xamarin.Android 上使用 FontAwesome 图标?
最佳答案
我的工作如下:
将 FontAwesome
ttf 文件复制到 Assets
文件夹。然后在Activity
页面的OnCreate()
方法下,控件应引用字体文件,如下所示:
Activity 页面:
Typeface font = Typeface.CreateFromAsset(Application.Assets, "fontawesome-webfont.ttf");
TextView txtv = (TextView)FindViewById(Resource.Id.textviewtitle);
txtv.Typeface = font;
.xaml 页面:
<TextView android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:editable="false"
android:text="\uf238 Unicode To get FontAwesome icon"
android:textSize="20dp"
android:textColor="#545454"
android:textStyle="bold"
android:padding="6dp"
android:id="@+id/textviewtitle"
/>
正如您在上面的 .xaml
页面代码 android:text="\uf238 Unicode To get FontAwesome icon"
中看到的,我已声明 \uf238
.这是特定图标的 unicode
。每个图标都有唯一的 unicode
。因此,我们应该始终使用 unicode
字符来获取控件或文本上显示的任何图标。
关于android - 如何在 Xamarin Android 中使用 FontAwesome 图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46804232/