1

如何在 Xamarin Forms 项目的 android 应用程序的所有页面中更改 ActionBar 的可见性。我在主要活动中使用了 ActionBar.Hide() ,但它仅在首页中隐藏它。

namespace ParsellIT.Droid
{
    [Activity(Label = "ParsellIT", MainLauncher = true)]
    public class MainActivity : AndroidActivity
    {
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            Xamarin.Forms.Forms.Init(this, bundle);            
            SetPage(App.GetMainPage());
            ActionBar.Hide();    
        }
    }
}

我想将它隐藏在每个页面中,但我无法访问 android 特定代码中的每个页面,因为它们是在 PCL 中构建的。有什么办法吗?

4

2 回答 2

3

更好的选择是调用:

global::Xamarin.Forms.Forms.SetTitleBarVisibility(Xamarin.Forms.AndroidTitleBarVisibility.Never)

或者

var page = App.GetMainPage();
Xamarin.Forms.NavigationPage.SetHasNavigationBar(page, true)

或在 xaml

<ContentPage
    xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    x:Class="Mobile.Views.NewsFeedSearchView"
    NavigationPage.HasNavigationBar="{Binding IsFullScreen}"/>
于 2015-07-25T22:47:56.930 回答
1

您应该在应用程序中使用没有操作栏的主题。例如,您可以在应用程序中指定应用程序属性:

[assembly: Application(Icon = "@drawable/Icon" Theme = "@android:Theme.Holo.Light.NoActionBar")]

或者你可以在 AndroidManifaset.xml 中设置

<application android:theme="@android:style/Theme.Holo.Light.NoActionBar" />

UPD 当然主题设置必须在 Android 项目中进行,但即使在 PCL 中也会影响到每个页面。

于 2014-07-17T04:26:57.663 回答