svg 图标未显示在工具栏项目中

svg icon not showing up in tool bar item

为什么我的 svg 没有显示?此图像位于可绘制文件夹下,构建操作设置为 AndroidResouces

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

我也试过将此图像放在共享文件夹下并将构建操作设置为嵌入资源,但图像没有显示

我也试过 但是 svg 图像没有显示,因为我需要将 fontfamily 设置为“FAS”但是 toobaritem 没有那个 fontfamily 属性

<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")]

你可以尝试给它一个高度和宽度

<ToolbarItem Name="Edit" Order="Primary" Priority="0" />
<ToolbarItem Text="{StaticResource ellipsisV}" Order="Primary" Priority="1" WidthRequest="60" HeightRequest="30"  />

Android 不支持 svg 文件,因此您需要使用 Android Studio 将它们转换为 Android xml 可绘制对象(并且不适用于所有 svg 文件。

除此之外,您还可以安装一些软件包,例如 Xamarin.Forms.Svg,它可以处理将 svg 转换为 ImageSource

正如 Ivan Ičin 所说 above.Android 不支持 svg 文件,您可以使用一些常用的第三方控件显示 SVG。

喜欢FFImageLoading

您可以将它与 NavigationPage.TitleView 一起使用。

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

或者您可以自定义布局来代替 ToolBarItem