我的xamarin andorid项目在Drawawble
下没有Resources
文件夹,我有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
- 将图像放在/mipmap/icon.png
Android
- 将图像放在/mipmap/drawable/icon.png