繁体   English   中英

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 图像没有显示 bc 我需要将 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>

汇编信息.cs

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

正如 Ivan Ičin 所说。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

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

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

Android doesn't support svg files, so you need to convert them to Android xml drawable using Android Studio if you really need that (and it doesn't work well for all svg files).

Other than that you could install some package like Xamarin.Forms.Svg that should handle this conversion of svg to ImageSource .

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM