android - 如何在 Xamarin Android 中使用 FontAwesome 图标

标签 android xamarin xamarin.android font-awesome

我正在开发一个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/

相关文章:

android - 验证登录屏幕的 GET JSON 响应并转到主屏幕

android - 为什么 Xamarin Android 无法发送 GRPC/Http2 请求?

c# - ListView 没有取消选择

android - Activity 结束时如何避免明确通知

java - 如何删除 SQLite 数据库中的条目?

android - 标签没有显示出来

ios - 删除导航栏中的后退箭头,保留后退按钮标题

c# - Xamarin 中的 Objective-c 绑定(bind)问题

android - BadTokenException : Unable to add window -- window android. view.ViewRootImpl$W@cb70704 已在三星设备上添加

android - 错误 1316 : while installing Mono for android on windows 7 (and visual studio 2010)