【问题标题】:Insert icon in a tabbed page(Android) on xamarin form在 xamarin 表单上的选项卡式页面(Android)中插入图标
【发布时间】:2017-12-13 14:10:51
【问题描述】:

我是 StackOverflow 社区的新手!
我需要有关 Xamarin Forms 中 android 的一个问题的帮助。准确地说...我尝试和一些朋友一起构建我们的第一个应用程序。我们选择(在我们大学教授的帮助下)Xamarin 用于使用 Xamarin 表单的两个系统的 Android 和 iOS 的跨平台开发。我创建了应用程序的界面部分,现在我被困在一个有大墙的堡垒中。当我尝试为功能栏添加选项卡式页面时,应用程序崩溃(Android),但在 iOS 中,问题没有出现......

我会尝试一些解决方案...例如:

-NameApp.Droid 中的Render 只为android 部分添加不同的渲染器,但没有结果... - 尝试另一种方式直接在.xaml文件中插入图标​​但没有结果... -尝试按照另一种方式修改“主题”部分的.axam文件 但没有结果...

我只想在“主项目”中按时整合所有的东西。我暂时不想触摸“nameProject.Droid”或“nameProject.iOS”部分,但尝试同时拍摄(Andriod 和 iOS)。我在 Android (è.é) 中发现了一个不同的错误,但为此,我快疯了…… 但是我需要修改“.Droid”没问题我接受挑战!


这是我渴望创造的结果。 "https://storage.googleapis.com/material-design/publish/material_v_12/assets/0B6Okdz75tqQsbHJuWi04N0ZIc0E/components-tabs-usage-mobile7.png"

这是我在标签页中添加图标的方式。假设我在“.Droid”和“.iOS”的“资源”中添加了所有东西:

        var MainPageTabbed = new MPageTabbed();

        var Profile = new Profile();

        var ListChat = new ListChat();

        if (Device.RuntimePlatform == Device.Android)
        {
            MainPageTabbed.Icon = "ldpi.png";
            Profile.Icon = "ldpi2.png";
            Chat.Icon = "ldpi1.png";

        }

        if (Device.RuntimePlatform == Device.iOS)
        {
            MainPageTabbed.Icon = "ldpi.png";
            Profile.Icon = "ldpi2.png";
            ListChat.Icon = "ldpi1.png";

        }
        NavigationPage.SetHasNavigationBar(this, false); 

        Children.Add(MainPageTabbed);
        Children.Add(Profile);
        Children.Add(ListChat);

有人可以帮我找到解决方案吗?

【问题讨论】:

  • 这不是 Xamarin.Forms 内置函数。 Xamarin.Forms 不会像在屏幕截图中那样获取图标并显示它。您必须为此实现创建一个自定义渲染器(参见此处:developer.xamarin.com/guides/xamarin-forms/…)。默认情况下,iOS 在底部显示此栏并带有图标。 Android 仅显示选项卡中的文本(在导航栏下)。没有图标。

标签: android xaml xamarin xamarin.forms xamarin.android


【解决方案1】:

这里有一个如何在 xamarin 表单中使用 TabbedPage 的示例:

https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/navigation/tabbed-page/

...Xamarin.forms 将 Android 选项卡式页面呈现为称为 viewpager 与 TabPagerStrib 组合的东西,它看起来像上面链接中的示例。

您可以改为阅读有关 Android 的 BottomNavigationBar,或查看此链接以获取带有图片的 TabPagerStrip

https://forums.xamarin.com/discussion/39937/adding-icons-to-a-pagertabstrip-instead-of-text

【讨论】:

    【解决方案2】:

    如果有人对 FontAwesome 自定义图标实现感兴趣,我会按照本教程开始:FontAwesome with Xamarin Forms

    不幸的是,他没有给出与选项卡式页面集成的示例,但经过一些试验后,我终于找到了一种简化的 Xaml 方法来呈现它,而无需自定义选项卡式渲染器:

    <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:IBMobile.Views"
             xmlns:local2="clr-namespace:FontAwesome"
             x:Class="IBMobile.Views.HomePage"
             Visual="Material">
    <ContentPage.IconImageSource>
        <FontImageSource FontFamily="{StaticResource FontAwesomeSolid}" Glyph="{x:Static local2:IconFont.Home}" />
    </ContentPage.IconImageSource>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-03-31
      • 1970-01-01
      • 2021-12-30
      • 2018-02-25
      • 2017-03-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多