如何从应用程序中删除操作栏?

How do I remove the action bar from the app?

我试图从我在 NativeScript 中开发的应用程序中删除操作栏,我删除了与操作栏相关的所有代码(html 和 css 代码) 但它继续出现在应用程序中。

HTML:

<ScrollView>
    <StackLayout class="page p-t-15">

            <Image src="~/app/img/logo.png" ></Image>
            <Label class="m-t-10 text-center" text="Login" label.Alignment = "top";></Label>

        <TextField class="m-t-10 m-b-10 m-l-15 m-r-15" hint="Email Address" keyboardType="email" autocorrect="false" autocapitalization="none"
            [(ngModel)]="email"></TextField>

        <TextField class="m-t-10 m-b-10 m-l-15 m-r-15" hint="Password" secure="true" autocorrect="false" autocapitalization="none"
            [(ngModel)]="password"></TextField>

        <Button class="btn btn-primary" text="SIGN IN" (tap)="onSigninButtonTap()"></Button>

        <Label class="m-t-10 text-center" text="______ or ______"></Label>

        <Button class="btn btn-outline" (tap)="onLoginWithSocialProviderButtonTap()" text="Log in with Social Provider"></Button>

        <Label class="m-t-10 m-b-10 m-l-15 m-r-15" text="Forgot password?" (tap)="onForgotPasswordTap()"></Label>

        <Label class="m-t-10 m-b-10 m-l-15 m-r-15" text="Não tem conta?" (tap)="onNaoTemContaTap()"></Label>
        <Button class="btn btn-primary" text="Sign UP" [nsRouterLink]="['/browse']" pageTransition="slide" clearHistory="true"></Button>
    </StackLayout>
</ScrollView>

CSS:

    StackLayout {
    height: 100%;
    width: 100%;
    background-image: linear-gradient(#000000,#439B9B , #000000); 
}

在要删除操作栏的页面中,添加 import { Page } from "tns-core-modules/ui/page";,然后在构造函数中添加 private page: Page。然后,您可以执行 this.page.actionBarHidden = true;.

有点像下面这样:

import { Page } from "tns-core-modules/ui/page";
...
export class ... {
    constructor(private page: Page) {
        this.page.actionBarHidden = true;
    }
    ...
}

注意:此代码仅适用于 angular 的 nativescript,该想法适用于 vanilla nativescript 但代码不同

使用 NativeScript 5.0,您在 Frame 组件上有一个新的 属性 actionBarVisibility。您可以将其设置为 never,并且您将永远不会在此 Frame 中导航的页面中看到 ActionBar。它消除了在每个页面上手动隐藏 ActionBar 的需要。

Angular 中的 page-router-outlet 组件公开了相同的 属性。

在 page-router-outlet 上设置 actionBarVisibility 非常有效。谢谢,马丁!