-2

I´m developing an app in xamarin forms and I want to know how show an icon in a menu, the image of this icon is in the resource folder (drawable). The menu is in a Inavigation page in the same project.

I´m trying this with the next code, but it doesn´t work:

*var iconlogin = new ToolbarItem
{
  Icon = "login.png"};*`

  *new Sample("Login", typeof(LoginPage), SampleData.DashboardImagesList[0], iconlogin.Icon, false, false)*
Gowtham S
  • 923
  • 14
  • 39

1 Answers1

0

How can I show an icon in xamarin?

Add the following code :

var settings = new ToolbarItem
{
    Icon = "icon.png",
    Text = "Settings",
};

this.ToolbarItems.Add(settings); //<-- this line

The icon.png in located in Resource\Drawable folder. If you want use the ToolbarItem in xaml, you need do :

<ContentPage.ToolbarItems>
    <ToolbarItem Name="Menu1" Activated="OnClick"  Order="Primary" Priority="0"  Icon="icon.png" />
    <ToolbarItem Name="Menu2" Activated="OnClick"  Order="Primary" Priority="1" />
</ContentPage.ToolbarItems>

Effect :

enter image description here

For more information, you could refer to the document or this question.

York Shen
  • 9,014
  • 1
  • 16
  • 40