如何在xamarin中显示图标?

时间:2017-10-24 10:06:20

标签: android xamarin icons

我正在开发一个xamarin表单的应用程序,我想知道如何在菜单中显示一个图标,该图标的图像位于资源文件夹(drawable)中。该菜单位于同一项目的Inavigation页面中。

我正在尝试使用下一个代码,但它不起作用:

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

  *new Sample("Login", typeof(LoginPage), SampleData.DashboardImagesList[0], iconlogin.Icon, false, false)*

1 个答案:

答案 0 :(得分:0)

  

如何在xamarin中显示图标?

添加以下代码:

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

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

位于icon.png文件夹中的Resource\Drawable。如果您想使用ToolbarItem中的xaml,则需要执行以下操作:

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

效果:

enter image description here

有关详情,请参阅document或此question