Search code examples
c#androidsvgxamarin.formsxamarin.android

svg icon not showing up in tool bar item


Why is my svg not showing up? This image is under drawable folder and build action is set to AndroidResouces

<ContentPage.ToolbarItems>
    <ToolbarItem Name="Edit" Order="Primary" Priority="0" />
    <ToolbarItem IconImageSource="ellipsisV.svg" Order="Primary" Priority="1" />
</ContentPage.ToolbarItems>

I also tried putting this image under shared folder and setting build action to embedded resources but image is not showing up

I also tried this but svg image doesnt show up bc i need to set fontfamily to "FAS" but toobaritem doesnt have that fontfamily property

<ContentPage.ToolbarItems>
    <ToolbarItem Name="Edit" Order="Primary" Priority="0" />
    <ToolbarItem Text="{StaticResource ellipsisV}" Order="Primary" Priority="1" />
</ContentPage.ToolbarItems>

app.xml

<x:String x:Key="ellipsisV">&#xf142;</x:String>

assemblyinfo.cs

 [assembly: ExportFont("FontAwesome-Free-Solid-900.otf", Alias = "FAS")]

Solution

  • As Ivan Ičin said above.Android doesn't support svg files,you could display SVG with some commonly used third-party controls.

    Like FFImageLoading

    You could use it with NavigationPage.TitleView.

    <NavigationPage.TitleView>
       <StackLayout  Orientation="Horizontal" HorizontalOptions="End" VerticalOptions="FillAndExpand">
           <Label Text = "Edit"  VerticalOptions="Center" />
           <ffimageloadingsvg:SvgCachedImage Source="ellipsisV.svg"/>
       </StackLayout>
    </NavigationPage.TitleView>
    

    or you could customize a layout in place of ToolBarItem.