如何在第一页显示之前隐藏导航栏?

时间:2016-06-14 10:22:20

标签: c# android xamarin xamarin.android xamarin.forms

我正在使用Xamarin Android构建Xamarin.Forms应用我的App类非常简单,并且包含一个页面,如下所示:

public App()
{
    // The root page of your application
    MainPage = new NavigationPage(new ContentPage()
    {
        Title = "My First Page!",
        Content = new Label()
        {
            Text = "Test Page!",
            TextColor = Color.White,
            FontSize = 25,
            HorizontalOptions = LayoutOptions.Center,
            VerticalOptions = LayoutOptions.Center
        }
    });
}

和我的MainActivity类一样:

[Activity(Label = "GridTest", Icon = "@drawable/icon", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsApplicationActivity
{
    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);

        global::Xamarin.Forms.Forms.Init(this, bundle);
        LoadApplication(new App());
    }
}

当我启动应用程序时,虽然NavigationBar显示左上方显示的单词“GridTest”,看起来很垃圾,如下所示:

这是我想要隐藏的NavigationBar。

enter image description here

在此之后我的应用程序加载导航栏很好。如下所示:

我想保留此导航栏

enter image description here

所以我的问题是。如何隐藏初始页面已加载之前的Android NavigationBar

侧面注意:

我尝试了NavigationPage.SetHasNavigationBar(page,false);,但这不起作用。这会隐藏下面显示的第一页的NavigationBarenter image description here

我想保留!这也不会隐藏我想要隐藏的“GridTest”导航栏(如屏幕截图1所示)

重申......我希望隐藏 INITIAL 导航栏。由Android MainActivity NOT Xamarin.Forms导航栏

提供

2 个答案:

答案 0 :(得分:2)

第一次启动应用程序时将加载的主要活动。

[Activity(Label = "testapp", MainLauncher = true, Theme = "@style/MyTheme", ScreenOrientation = ScreenOrientation.Portrait)]
    public class SplashActivity : Activity
    {
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
           // SetContentView(Resource.Layout.LaunchScreen); //Set a splash screen here if you wish
            Java.Lang.Runnable runnable = new Java.Lang.Runnable(() =>
            {
                Intent i = new Intent(this, typeof(MainActivity));
                StartActivity(i);
            });

            new Handler().PostDelayed(runnable, 1000);
        }
    }

该活动的主题必须保存到Resources/drawable/styles.xml并且

<resources>
  <style name="MyTheme" parent="Theme.AppCompat.NoActionBar">
    <item name="android:windowNoTitle">true</item>
  </style>
</resources>

SplashActivity将加载并调用MainActivity

,您的MainActivity将如下所示:

[Activity(Label = "GridTest", Icon = "@drawable/icon", ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsApplicationActivity
{
    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);

        global::Xamarin.Forms.Forms.Init(this, bundle);
        LoadApplication(new App());
    }
}

你不需要在这里设置主题,它将像以前一样工作。关于MainActivity的另一个重要注释是必须删除MainLauncher = true

答案 1 :(得分:0)

您应该可以通过在页面中设置简单属性来隐藏该导航栏,如下所示: <ContentPage NavigationPage.HasNavigationBar="false" ..... > </ContentPage>

相关问题