2

I am developing an xamarin Android application and need to use FontAwesome icons in application. But don't know how to use it. Got lot's of articles on internet but it's not clear to me.

How to use FontAwesome icons on Xamarin.Android?

James Z
  • 12,209
  • 10
  • 24
  • 44
Sumeet Kumar
  • 321
  • 4
  • 17
  • What have you tried so far, any code you have tried? There are lot of tutorials about adding font awesome to the asset folder and creating a helper class on the interweb. – jaymarvels Oct 18 '17 at 08:57
  • Sir I have tried these 2 tutorial's [tutorial 1](https://forums.xamarin.com/discussion/31530/fontawesome-label-heres-how), [tutorial 2](https://kimsereyblog.blogspot.in/2016/12/use-font-awesome-from-your-xamarinforms.html) – Sumeet Kumar Oct 18 '17 at 08:59
  • but as I have tried the code they have provided in these articles It showing me an error under each line of code. `type or namespace could not be found(are you missing a using directive or an assembly reference?)` – Sumeet Kumar Oct 18 '17 at 09:04

2 Answers2

2

I have got worked as below:

Copy FontAwesome ttf file to Assets folder. Then under OnCreate() method of Activity page the control should be referred to the font file as below:

Activity Page:

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

.xaml Page:

<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"
                  />

As you see above in .xaml Page code android:text="\uf238 Unicode To get FontAwesome icon", I have declared \uf238. This is unicode for the particular icon. Every Icon would have unique unicode. Therefore we should use always unicode character to get any icon displayed on control or on text.

cherry
  • 517
  • 5
  • 12
Sumeet Kumar
  • 321
  • 4
  • 17
1

Found this on web use following github repo to get Xamarin.Plugins it has

Font Awesome, Ionicons, Material design icons, Meteocons

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

Nisal Edu
  • 7,237
  • 4
  • 28
  • 34
  • Sir, there are lots of folders. Which folder should I have to access ? – Sumeet Kumar Oct 24 '17 at 05:07
  • go to following link and read readme https://github.com/JoanZapata/android-iconify – Nisal Edu Oct 24 '17 at 05:36
  • 1
    Sir the link that you have shared is for xamarin.Forms App. right ? I need for xamarin.Android. . – Sumeet Kumar Oct 24 '17 at 08:58
  • Did you go to last link I commented – Nisal Edu Oct 24 '17 at 09:01
  • android:text="I {fa-heart-o} to {fa-code} on {fa-android}" Check readme – Nisal Edu Oct 24 '17 at 09:03
  • It has defined to use `@Override public void onCreate()` now how should I convert it to xamarin ? – Sumeet Kumar Oct 24 '17 at 09:03
  • Sir, they have suggested to define **dependencies**. In my application where should I define these dependencies ? – Sumeet Kumar Oct 24 '17 at 09:05
  • Sir, I have got 1 reference link as : [https://stackoverflow.com/questions/15210548/how-to-use-icons-and-symbols-from-font-awesome-on-native-android-application](https://stackoverflow.com/questions/15210548/how-to-use-icons-and-symbols-from-font-awesome-on-native-android-application). In this referece they have used `getAssets() ` method. What is it ? and how to use it? – Sumeet Kumar Oct 25 '17 at 11:12
  • https://stackoverflow.com/questions/8458433/getassets-from-another-class – Nisal Edu Oct 25 '17 at 11:18