我的xamarin andorid项目在Resources下没有Drawawble文件夹,我有mipmap文件夹.我正在尝试为共享项目中的工具栏项设置图标.如果我将图像设置为嵌入资源,我应该能够从共享项目中访问它,我错了吗?
<?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="BoringAppUi.MainPage" Title="Main Page"> <ContentPage.toolbaritems> <ToolbarItem Text="logout" Clicked="OnlogoutButtonClicked" Order="Primary" Priority="0"/> <ToolbarItem Text="Home" Icon="@mipmap/baseline_home_blue_48.png" Clicked="OnHomeIconClicked" Order="Primary" Priority="1"/> </ContentPage.toolbaritems> <ContentPage.Content> <StackLayout> <Label Text="Main app content goes here" HorizontalOptions="Center" VerticalOptions="CenterandExpand" /> </StackLayout> </ContentPage.Content> </ContentPage>
我也尝试从后面的代码设置它
var toolbarItemHome = new ToolbarItem { Text = "Home",Icon = "@mipmap/baseline_home_blue_48.png" }; toolbarItemHome.Clicked += OnHomeIconClicked; toolbaritems.Add(toolbarItemHome);
解决方法
来自c#代码:
new ToolbarItem () { Icon = "icon.png"}
或者来自xaml:
<ToolbarItem Name="iconexample" Icon="icon.png" Priority="0" Order="Primary" Activated="Onclick" />
主要有:
iOS - place the image at /mipmap/icon.png Android - place the image at /mipmap/drawable/icon.png