【问题标题】:svg icon not showing up in tool bar itemsvg 图标未显示在工具栏项中
【发布时间】:2021-08-24 03:33:45
【问题描述】:

为什么我的 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")]

【问题讨论】:

    标签: c# android svg xamarin.forms xamarin.android


    【解决方案1】:

    正如 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

    【讨论】:

    • 我添加到使用 xamari.n.forms 所以不得不使用&lt;Shell.TitleView&gt; 但很棒的东西。感谢您的帮助
    【解决方案2】:

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

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

    【讨论】:

      【解决方案3】:

      Android 不支持 svg 文件,因此如果您确实需要,您需要使用 Android Studio 将它们转换为 Android xml drawable(并且它不适用于所有 svg 文件)。

      除此之外,您还可以安装一些像 Xamarin.Forms.Svg 这样的包来处理 svg 到 ImageSource 的这种转换。

      【讨论】:

      • 我能够将 svg 图像转换为可绘制的 xml 文件。我如何加载这个 cml 图像?
      猜你喜欢
      • 2018-01-27
      • 2014-03-04
      • 2016-12-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多