Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove (Android) app title bar in Xamarin.Forms?

Is there any chance that I can remove the title bar of the app in Xamarin.Forms? I am working on a Xamarin.Forms Portable project. I tried a lot of solutions, but neither worked, I couldn't even start the app.

First attempt I tried adding this to my AndroidManifest.xml, didn't work:

android:theme="@android:style/Theme.NoTitleBar"

Second attempt I tried creating a styles.xml in Resources/values, which was:

<?xml version="1.0" encoding="utf-8" ?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
  <style name="Theme.Default" parent="@android:style/Theme"></style>
  <style name="Theme.NoTitle" parent="@android:style/Theme.NoTitleBar"></style>
  <style name="Theme.FullScreen" parent="@android:style/Theme.NoTitleBar.Fullscreen"></style>
</resources>

And then I added this to my AndroidManifest.xml (didn't work either)

android:theme="@style/Theme.NoTitle"

Third attempt I tried adding this to my OnCreate method in MainActivity.cs (didn't work).

RequestWindowFeature(WindowFeatures.NoTitle);

Can anyone help me with this?

like image 977
Szandi Avatar asked Jun 23 '16 08:06

Szandi


3 Answers

This can be done in PCL:

 var page = new LoginPage();
 NavigationPage.SetHasNavigationBar(page, false); // call this method every time before you push a page (no title bar)
 await navigation.PushAsync(page); 

If you are using old FormsApplicationActivity, try, add this in OnCreate(Bundle bundle) method

protected override void OnCreate(Bundle bundle)
{
    base.OnCreate(bundle)

    Forms.SetTitleBarVisibility(AndroidTitleBarVisibility.Never);
    Forms.Init(this, bundle);
}

This one seems do the app wide setting, but I am not so sure, as I don't use FormsApplicationActivity anymore.

like image 148
Bonelol Avatar answered Nov 09 '22 05:11

Bonelol


If you want to remove the title bar on the initial page, the quickest and easiest way to do it is to go to to the contentpage heading in your XAML for the page and type

NavigationPage.HasNavigationBar="False"

so the XAML would like something like this

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="YourClass.YourPage"
             NavigationPage.HasNavigationBar="False">
like image 42
Jeff Jose Avatar answered Nov 09 '22 04:11

Jeff Jose


Using the latest version of Xamarin.Forms I found that if you use:

await Navigation.PushAsync(new NextPage())

//Title on NextPage is displayed

await Navigation.PushModalAsync(new NextPage())

//Title on NextPage is not displayed

Nathan

like image 3
Nathan Robeson Avatar answered Nov 09 '22 06:11

Nathan Robeson