使用 Xamarin Forms,如何在不显示导航栏的情况下更改页面?
Using Xamarin Forms, How can I change page without displaying a navigation bar?
我想更改 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
从图中可以看出,顶部还有一个带有图标的栏
谢谢
我相信你必须在内页上调用 NavigationPage.SetHasNavigationBar (),而不是 NavigationPage(在你的情况下是我的页面)尝试执行以下操作:
var pageOne = new PageOne();
NavigationPage.SetHasNavigationBar (pageOne, false);
NavigationPage mypage = new NavigationPage (pageOne);
MainPage = mypage;
编辑如何从 Android 上的加载屏幕中删除导航栏(基本上设置一个具有简单图像背景的虚拟初始页面,并在加载时重定向到真正的主页面 activity(此时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>
除了 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">
我想更改 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
从图中可以看出,顶部还有一个带有图标的栏
谢谢
我相信你必须在内页上调用 NavigationPage.SetHasNavigationBar (),而不是 NavigationPage(在你的情况下是我的页面)尝试执行以下操作:
var pageOne = new PageOne();
NavigationPage.SetHasNavigationBar (pageOne, false);
NavigationPage mypage = new NavigationPage (pageOne);
MainPage = mypage;
编辑如何从 Android 上的加载屏幕中删除导航栏(基本上设置一个具有简单图像背景的虚拟初始页面,并在加载时重定向到真正的主页面 activity(此时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>
除了 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">