代码之家  ›  专栏  ›  技术社区  ›  Ahmer Ali Ahsan

使用角度模板在nativescript中隐藏状态栏的正确方法是什么?

  •  0
  • Ahmer Ali Ahsan  · 技术社区  · 5 年前

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

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

    Ref # 1

    Ref # 2

    Ref # 3

    Ref # 4

    getWindow 在genymotion andriod虚拟机上运行我的应用程序时。下面是简短的错误屏幕截图

    enter image description here

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

    请帮我解决这个问题。谢谢。

    0 回复  |  直到 5 年前
        1
  •  1
  •   Manoj    5 年前

    你可能想用 nativescript-status-bar 插件。

    import * as statusBar from 'nativescript-status-bar'
    
    // Show
    statusBar.show();
    
    // Hide
    statusBar.hide();
    
        2
  •  0
  •   Yatin Kapur    4 年前

    var activity = app.android.foregroundActivity || app.android.startActivity;
    var window = activity.getWindow();
    window.clearFlags(android.view.WindowManager.LayoutParams.FLAG_FULLSCREEN)
    
        3
  •  0
  •   KielSoft    4 年前
    if(isAndroid){
        Application.android.startActivity.getWindow().getDecorView().setSystemUiVisibility(android.view.View.SYSTEM_UI_FLAG_FULLSCREEN)
    }
    

    上面的代码可以让您在android设备上隐藏状态栏,而关于的代码片段在Nativescript7和更高版本上运行良好。