fantaseador
fantaseador

Reputation: 99

Hiding Android Action Bar in Xamarin PCL project

How to change the visibility of the ActionBar in all pages of an android app in a Xamarin Forms project. I used ActionBar.Hide() in the main activity but it hides it only in the front page.

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();    
        }
    }
}

I want to hide it in every page but I cant access every page in the android specific code as they are built in PCL. Is there any way to do so?

Upvotes: 1

Views: 4022

Answers (2)

Ahmed Alejo
Ahmed Alejo

Reputation: 2431

A better option is to call:

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

or

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

or in 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}"/>

Upvotes: 3

ad1Dima
ad1Dima

Reputation: 3195

You should use Theme with no Action bar in your app. For ex, you can specify Application Attribute somewere in your app:

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

Or you can set it in AndroidManifaset.xml

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

UPD Of course theme settings must be done in Android project, but it will affect on each page even in PCL.

Upvotes: 1

Related Questions