如何在 Xamarin Android 中使用 FontAwesome 图标

Posted

技术标签:

【中文标题】如何在 Xamarin Android 中使用 FontAwesome 图标【英文标题】:How to Use FontAwesome Icon in Xamarin Android 【发布时间】:2017-10-18 06:45:01 【问题描述】:

我正在开发一个 xamarin android 应用程序,需要在应用程序中使用 FontAwesome 图标。但是不知道怎么用。网上有很多文章,但我不清楚。

如何在 Xamarin.Android 上使用 FontAwesome 图标?

【问题讨论】:

到目前为止您尝试过什么,您尝试过什么代码?有很多关于在资产文件夹中添加字体真棒和在互联网上创建帮助类的教程。 先生,我已经尝试了这两个教程的tutorial 1,tutorial 2 但是当我尝试了他们在这些文章中提供的代码时,它在每一行代码下都显示了一个错误。 type or namespace could not be found(are you missing a using directive or an assembly reference?) 【参考方案1】:

我的工作如下:

FontAwesome ttf 文件复制到Assets 文件夹。那么在Activity页面的OnCreate()方法下,控件应该参考字体文件如下:

活动页面:

Typeface font = Typeface.CreateFromAsset(Application.Assets, "fontawesome-webfont.ttf");
TextView txtv = (TextView)FindViewById(Resource.Id.textviewtitle);
txtv.Typeface = font;

.xaml 页面:

<TextView android:layout_
                    android:layout_
                    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 字符来获取控件或文本上显示的任何图标。

【讨论】:

【参考方案2】:

在 github repo 之后在 web 上找到这个以获取它拥有的 Xamarin.Plugins

Font Awesome、Ionicons、Material design 图标、Meteocons

https://github.com/jsmarcus/Xamarin.Plugins/tree/master/Iconize

【讨论】:

先生,有很多文件夹。我应该访问哪个文件夹? 转到以下链接并阅读自述文件github.com/JoanZapata/android-iconify 先生,您共享的链接适用于 xamarin.Forms App。对 ?我需要 xamarin.Android。 . 你去我评论的最后一个链接了吗 android:text="I fa-heart-o to fa-code on fa-android" 查看自述文件

以上是关于如何在 Xamarin Android 中使用 FontAwesome 图标的主要内容,如果未能解决你的问题,请参考以下文章

在xamarin android中填充软输入调整大小

如何在 Xamarin Android 中使用 FontAwesome 图标

如何在 Xamarin(iOS 和 Android)应用程序中使用 Windows 命名空间?

如何在 Xamarin.Android 中使用 mipmap 文件夹?

如何在 Xamarin 中使用具有 android/IOS 特定视图的控制模板

如何在 xamarin android ui 测试自动化中使用日期选择器