簡體   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