【问题标题】:What is the right way to hide the status bar in nativescript using angular template?使用角度模板在nativescript中隐藏状态栏的正确方法是什么?
【发布时间】:2020-11-30 04:18:57
【问题描述】:

如何隐藏特定活动的状态栏?

我发现了这个类似的问题,但没有一个答案对我有用。

Ref # 1

Ref # 2

Ref # 3

Ref # 4

该应用程序每次都崩溃并显示错误无法读取属性getWindow 在genymotion andriod VM 上运行我的应用程序时。以下是简短的错误屏幕截图

下面是我的 home.component.ts 代码

import { Component, OnInit } from "@angular/core";
import {Page} from "ui/page";
import * as app from "tns-core-modules/application";

@Component({
    selector: "Home",
    moduleId: module.id,
    templateUrl: "./home.component.html",
    styleUrls: ["./home.component.scss"]
})
export class HomeComponent implements OnInit {

    constructor(page: Page) {
        page.actionBarHidden = true;
        this.statusBar('hide');
    }

    ngOnInit(): void {

        // Init your component properties here.
    }

    statusBar(action: string){
        var activity = app.android.startActivity;
        //activity.runOnUiThread(function(){
        var win = activity.getWindow();
        if(action === 'hide'){
            win.addFlags(app.android.nativeApp.view.WindowManager.LayoutParams.FLAG_FULLSCREEN);
        } else if(action === 'show'){
            win.clearFlags(app.android.nativeApp.view.WindowManager.LayoutParams.FLAG_FULLSCREEN);
        }
    }
}

请帮助我。谢谢。

【问题讨论】:

    标签: nativescript angular2-nativescript


    【解决方案1】:

    您可能想使用nativescript-status-bar 插件。

    import * as statusBar from 'nativescript-status-bar'
    
    // Show
    statusBar.show();
    
    // Hide
    statusBar.hide();
    

    【讨论】:

    • 在我上面的参考文献中我提到了这个插件链接。我在我的家庭组件中尝试了这个,并使用了显示和隐藏方法,但它仍然没有隐藏状态栏。第二件事是我可能需要在我的 module.ts 中添加一些我不知道的东西。这就是它不起作用的原因。
    • 它对我来说非常好用。如果您有问题,请分享 Playground 示例。
    • 这是我的游乐场play.nativescript.org/?template=play-ng&id=tz7RPF,但它在我的游乐场控制台中显示了一些设备错误错误错误:未捕获(承诺):错误:com.tns.NativeScriptException:找不到模块:“nativescript -status-bar”,相对于:app/tns_modules/
    • 您是否在 module.ts 文件或组件中导入了其他内容?
    • 在 Playground 中使用插件时,必须按照相对路径导入插件。其次,您过早地访问这些方法,要么等待根视图的加载事件,要么等待活动的创建事件。
    【解决方案2】:

    如果您正在寻找全屏查看应用程序和隐藏状态栏的解决方案,请使用:

    var activity = app.android.foregroundActivity || app.android.startActivity;
    var window = activity.getWindow();
    window.clearFlags(android.view.WindowManager.LayoutParams.FLAG_FULLSCREEN)
    

    【讨论】:

      【解决方案3】:
      if(isAndroid){
          Application.android.startActivity.getWindow().getDecorView().setSystemUiVisibility(android.view.View.SYSTEM_UI_FLAG_FULLSCREEN)
      }
      

      上面的代码可以让你在安卓设备上隐藏状态栏,sn-p about 在 Nativescript7 及更高版本上运行良好。

      您也可以在 onNgInit 方法中实现这一点,以便在导航到页面或组件时隐藏状态栏。

      【讨论】:

      • 请补充一些细节,解释你为什么发布这个代码
      猜你喜欢
      • 2021-02-20
      • 2021-10-11
      • 2022-09-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-06
      相关资源
      最近更新 更多