【问题标题】:Xamarin Forms IconsXamarin 窗体图标
【发布时间】:2017-11-11 16:02:00
【问题描述】:

我想知道如何在我的 Xamarin Forms 应用程序中实现图标。我想使用像 glyphicons 或 font awesome 之类的东西。但是,我不知道如何在我的 xaml/c# 页面中实现它。

理想情况下,我的目标是这样的:

如果有人可以提供代码来显示像搜索栏或三行这样的图标,那就太好了。我可以格式化它看起来很漂亮。我正在为如何真正拉入图标而苦苦挣扎!

【问题讨论】:

  • Google 提供了几个包来支持这一点。您甚至尝试过先搜索吗?
  • 是的,我所看到的一切都需要自定义渲染和我无法掌握的技术。 Iconize 似乎不适用于 Windows 手机。您能否提供适用于 iOS、Android 和 UWP 的软件包的名称?
  • @ConnorMeeks 你能看看我的回答吗,这就是我几年前第一次实现它的方式,非常好和容易,你不需要成为 Xamarin 专家。跨度>
  • 对于 xamarin 表单中的自定义字体,您可以使用 Blog
  • 您可以在此处使用派生的 Unicode:github.com/fzany/Font-Awesome-Cheat-Charp

标签: c# xaml xamarin xamarin.forms glyphicons


【解决方案1】:

看看 Xamarin Forms 的新版本,解决方案已经制定!我在https://stackoverflow.com/a/56257444/11305148 中发布了anwser

但是就这样吧。以下代码可以正常工作:

<Button  Text="Pesquisar">
    <Button.ImageSource>
         <FontImageSource Glyph="&#xf002;" FontFamily="{StaticResource FontIcon}"/>
    </Button.ImageSource>
</Button>

还有这个:

<ContentPage.ToolbarItems>
    <ToolbarItem>
        <ToolbarItem.IconImageSource>
             <FontImageSource Glyph="&#xf002;" FontFamily="{StaticResource FontIcon}"/>
        </ToolbarItem.IconImageSource>
    </ToolbarItem>
</ContentPage.ToolbarItems>

【讨论】:

    【解决方案2】:

    最简单的方法可能是使用https://github.com/jsmarcus/Xamarin.Plugins

    从 Visual Studio 或 Xamarin Studio,安装以下包:

    • Xam.Plugin.Iconize
    • Xam.Plugin.Iconize.FontAwesome
    • Xam.FormsPlugin.Iconize

    注意:如果你愿意,你可以安装 Xam.Plugin.Iconize.Material 和许多其他类似的东西。

    在Android项目中,MainActivity类,OnCreate()方法添加

    FormsPlugin.Iconize.Droid.IconControls.Init(Resource.Id.toolbar);
    Plugin.Iconize.Iconize.With(new Plugin.Iconize.Fonts.FontAwesomeModule());
    

    iOS项目中,AppDelegate类,FinishedLaunching()方法,添加类似行

    FormsPlugin.Iconize.iOS.IconControls.Init();
    Plugin.Iconize.Iconize.With(new Plugin.Iconize.Fonts.FontAwesomeModule())
    

    另外,在iOS项目中,添加info.plist

    <key>UIAppFonts</key>
    <array>     
        <string>iconize-fontawesome.ttf</string>
    </array>    
    

    现在,在您有工具栏的 XAML 中,在标签中添加

    <ContentPage ...
    xmlns:iconize="clr-namespace:FormsPlugin.Iconize;assembly=FormsPlugin.Iconize" ...
    >
    

    <ContentPage.ToolbarItems>
        <iconize:IconToolbarItem Order="Primary" Clicked="..." Icon="fa-search" IconColor="White" />
    </ContentPage.ToolbarItems>
    

    【讨论】:

    • 这适用于 Windows (UWP) 吗?我需要为这些文件做些什么吗?
    • 这适用于 Windows 吗?还是这是特定于 Android/iOS 的?
    • 不确定 Windows。
    • 在 UWP 上试过这个,遗憾的是它不适用于命令栏图标
    • 我正在可视化图标,但是当我单击它时它什么也没做。在 Iconlabel 它工作正常。 iOS的工具栏项也可以
    猜你喜欢
    • 2018-09-15
    • 2019-06-17
    • 2019-08-25
    • 2019-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-05
    相关资源
    最近更新 更多