简体   繁体   English

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

[英]svg icon not showing up in tool bar item

Why is my svg not showing up?为什么我的 svg 没有出现? This image is under drawable folder and build action is set to AndroidResouces此图像位于可绘制文件夹下,构建操作设置为 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我也试过这个,但是 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 app.xml

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

assemblyinfo.cs汇编信息.cs

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

As Ivan Ičin said above.Android doesn't support svg files,you could display SVG with some commonly used third-party controls.正如 Ivan Ičin 所说。Android 不支持 svg 文件,您可以使用一些常用的第三方控件显示 SVG。

Like FFImageLoadingFFImageLoading

You could use it with NavigationPage.TitleView .您可以将它与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 .或者您可以自定义布局来代替ToolBarItem

You can try to give it a Height and width你可以尝试给它一个高度和宽度

<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). 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 . 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