DEV Community

Peedroca
Peedroca

Posted on

Material font icons on Xamarin Forms

Hello devs 🖖, recently I'm searching how to use Materialize icons in my mobile app maked with Xamarin.Forms 4.8, but I could't find a great step by step. Therefore I will try to do it today.

Font Source

You need to download the TFF font at material design google repo, so go to material-design-icons > font > MaterialIcons-Regular.ttf.

Using font icon

Step 1. Put archieve tff on folder Fonts in your Xamarin Shared Project.

image

Don't forget to set build action as Embedded resource.

Step 2. Add ExportFont in your App.xaml.cs as below:

...

[assembly: ExportFont("MaterialIconsRegular.ttf", Alias = "Material")]
namespace MaterialApp
{
    public partial class App : Application
    {
        public App()
        {
            InitializeComponent();

            MainPage = new MainPage();
        }

...
Enter fullscreen mode Exit fullscreen mode

Alias is optional.

Step 3. Use a materialize font in any page you need.

<StackLayout>
    <Label Text="&#xe87C;" FontSize="50" TextColor="Orange"
           FontFamily="Material" HorizontalOptions="Center" />      
</StackLayout>
Enter fullscreen mode Exit fullscreen mode

You will need the hexadecimal code, You can get it at MaterialIcons-Regular.codepoints.

I like to search icons on https://material.io/resources/icons/?style=baseline and get theirs names, so I find the hexadecimal code at MaterialIcons-Regular.codepoints. (you can find it in google repo.)

That's all, folks. 😄

Oldest comments (3)

Collapse
 
vhugogarcia profile image
Victor Hugo Garcia

Very nice article. However, I could not find a way to use MaterialIcons rounded or outlined versions.

I'm wondering if you have implemented those versions.

Thanks in advance

Collapse
 
peedroca profile image
Peedroca

Thanks!

The rounded and outlined icons was added some months ago... Try get it here: github.com/google/material-design-...

Tell me if you got it!

Collapse
 
raselb_ profile image
Russell.

I followed the step by step instructions but my icon does not appear as intended. here's how it looks like.

Image description