【问题标题】:Using Xamarin Forms, How can I change page without displaying a navigation bar?使用 Xamarin Forms,如何在不显示导航栏的情况下更改页面?
【发布时间】:2015-05-06 22:49:09
【问题描述】:

我想更改 Xamarin Forms 中的页面,为此我读到您需要使用 NavigationPage 作为根页面。我的问题是我无法摆脱顶部的导航栏。我尝试过使用 SetHasNavigationBar,但它似乎不起作用

public App ()
{
    NavigationPage mypage = new NavigationPage (new PageOne ());
    NavigationPage.SetHasNavigationBar (mypage, false);
    MainPage = mypage;
}

结果:http://i870.photobucket.com/albums/ab261/j0sht/prob_zps4bmxtyvb.png

从图中可以看出,顶部还有一个带图标的栏

谢谢

【问题讨论】:

    标签: mobile xamarin xamarin.forms


    【解决方案1】:

    我相信您必须在内页上调用 NavigationPage.SetHasNavigationBar (),而不是 NavigationPage(在您的情况下为 mypage)尝试执行以下操作:

    var pageOne = new PageOne();
    NavigationPage.SetHasNavigationBar (pageOne, false);
    NavigationPage mypage = new NavigationPage (pageOne);
    MainPage = mypage;
    

    编辑如何从 Android 上的加载屏幕中消除导航栏(基本上设置一个具有简单图像背景的虚拟启动页面,并在加载时重定向到您的真实主要活动(此时 Xamarin Forms 接管):

    [Activity(MainLauncher = true, NoHistory = true, Theme = "@style/Theme.Splash",
    ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
    public class SplashScreen : Activity
    {
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
    
            var intent = new Intent(this, typeof(MainActivity));
            StartActivity(intent);
        }
    }
    

    以及启动画面的主题:

    <style name="Theme.Splash" parent="android:Theme">
        <item name="android:windowBackground">@drawable/splashscreen</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowIsTranslucent">false</item>
        <item name="android:windowIsFloating">false</item>
        <item name="android:backgroundDimEnabled">true</item>
    </style>
    

    【讨论】:

    • 非常感谢你的工作,还有 1 件事,如果我使用这个栏仍然会在加载页面时出现,我怎样才能避免它在加载时显示?
    • 很高兴有帮助!所以加载页面是一个有点棘手的问题——你必须在每个平台上独立解决这个问题。我已经在我的答案中添加了我用于 Android 的内容(基本上是一个带有图像的简单启动屏幕,而不是带有导航栏的空白屏幕)。对于iOS,您必须自己弄清楚,我不确定该怎么做!
    • 您也可以使用 AttachedProperties 在 Xaml 或全局样式中设置值
    【解决方案2】:

    除了 codechinchilla 的解决方案之外,您还可以通过附加属性在 XAML 中实现相同的结果:

    <ContentPage x:Class="MyComapany.MyProduct.Forms.Views.MyView"
                 NavigationPage.HasNavigationBar="False"
                 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                 xmlns="http://xamarin.com/schemas/2014/forms">
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-02-24
      • 2019-10-06
      • 1970-01-01
      • 2018-07-07
      • 1970-01-01
      • 2020-02-14
      • 2022-10-16
      相关资源
      最近更新 更多