【问题标题】:How to remove action bar in xamarin form?如何删除 xamarin 形式的操作栏?
【发布时间】:2019-12-19 16:50:34
【问题描述】:

我有一个 xamarin 表单应用程序。 我的应用程序的头部是这样的:

我想移除隐藏绿条(顺便说一句,它叫actionbar吗?)

我的 App.xaml 是这样的:

<?xml version="1.0" encoding="utf-8" ?>
<Application xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:d="http://xamarin.com/schemas/2014/forms/design"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             mc:Ignorable="d"
             x:Class="AddaDiLeonardo.App"
             NavigationPage.HasNavigationBar="False">

    <Application.Resources>
        <ResourceDictionary>
            <!--Global Styles-->
            <!--Color x:Key="NavigationPrimary">#FFFFFF</-->
            <Style TargetType="NavigationPage">
                <!--Setter Property="BarBackgroundColor" Value="{StaticResource NavigationPrimary}" /-->
                <Setter Property="BarBackgroundColor" Value="Green"/>
                <Setter Property="BarTextColor" Value="Red" />
            </Style>
        </ResourceDictionary>
    </Application.Resources>

</Application>

而我的 MainPage.xaml 是这样的:

<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
            xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
            xmlns:d="http://xamarin.com/schemas/2014/forms/design"
            xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
            mc:Ignorable="d"
            xmlns:views="clr-namespace:AddaDiLeonardo.Views"
            x:Class="AddaDiLeonardo.Views.MainPage"
            SelectedTabColor="Blue"
            UnselectedTabColor="DarkGray"
            BarBackgroundColor="White"
            Title="Adda di Leonardo"
            >
    <TabbedPage.Children>
        <!--Caricamento dinamico-->
    </TabbedPage.Children>

</TabbedPage>

我也尝试过编辑 xaml 文件、cs 文件和样式,但我无法弄清楚。

如果可能的话,我希望该解决方案同时适用于 android 和 ios。

感谢您的帮助!

【问题讨论】:

    标签: c# android ios xamarin xamarin.forms


    【解决方案1】:

    我解决了这个问题:

    NavigationPage.HasNavigationBar="False"
    

    不在 TabbedPage.xaml 或 App.xaml 中,而是在我在 TabbedPage 中加载的子页面中。

    【讨论】:

    • 如果你自己解决了这个问题,请标记你的答案,它将帮助其他有类似问题的人。
    【解决方案2】:

    在 .xaml 中尝试类似的操作

    <TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    NavigationPage.HasNavigationBar="False">
    

    【讨论】: