如何在Xamarin.Forms中删除(Android)应用程序标题栏?

Sza*_*ndi 9 c# xaml android xamarin.forms

我有没有机会在Xamarin.Forms中删除应用程序的标题栏?我正在开发一个Xamarin.Forms Portable项目.我尝试了很多解决方案,但都没有用,我甚至无法启动应用程序.

第一次尝试我尝试将其添加到我的AndroidManifest.xml,但没有用:

android:theme="@android:style/Theme.NoTitleBar"
Run Code Online (Sandbox Code Playgroud)

第二次尝试我尝试在Resources/values中创建一个styles.xml,它是:

<?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>
Run Code Online (Sandbox Code Playgroud)

然后我把它添加到我的AndroidManifest.xml中(也没用)

android:theme="@style/Theme.NoTitle"
Run Code Online (Sandbox Code Playgroud)

第三次尝试我尝试将其添加到MainActivity.cs中的OnCreate方法(不起作用).

RequestWindowFeature(WindowFeatures.NoTitle);
Run Code Online (Sandbox Code Playgroud)

谁能帮我这个?

小智 6

如果要删除初始页面上的标题栏,最快捷、最简单的方法是转到页面的 XAML 中的内容页面标题并键入

NavigationPage.HasNavigationBar="假"

所以 XAML 想要这样的东西

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="YourClass.YourPage"
             NavigationPage.HasNavigationBar="False">
Run Code Online (Sandbox Code Playgroud)


Bon*_*lol 4

这可以在 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); 
Run Code Online (Sandbox Code Playgroud)

如果您使用旧的 FormsApplicationActivity,请尝试将其添加到 OnCreate(Bundle bundle) 方法中

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

    Forms.SetTitleBarVisibility(AndroidTitleBarVisibility.Never);
    Forms.Init(this, bundle);
}
Run Code Online (Sandbox Code Playgroud)

这似乎是应用程序范围内的设置,但我不太确定,因为我不再使用 FormsApplicationActivity。