7
votes

My xamarin andorid project does not have Drawawble folders under Resources, I have mipmap folders instead. I'm trying to set icon for a toolbar item in shared project. If I set an image as embeded resource I should be able to access it from the shared project, am I wrong?

<?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>

Also I've tried setting it from the code behind

var toolbarItemHome = new ToolbarItem
{
    Text = "Home",
    Icon = "@mipmap/baseline_home_blue_48.png"
};
toolbarItemHome.Clicked += OnHomeIconClicked;
ToolbarItems.Add(toolbarItemHome);
1
Still looking for an answer?FreakyAli

1 Answers

9
votes

From c# code:

new ToolbarItem () { Icon = "icon.png"}

Or from xaml:

<ToolbarItem Name="iconexample" Icon="icon.png" Priority="0" Order="Primary" Activated="Onclick" />  

Have that in mind:

iOS - place the image at /mipmap/icon.png

Android - place the image at /mipmap/drawable/icon.png