我创建了一个非常小的应用程序,对于Android,它显示在加载第一页时进入沉浸式模式。我遇到的问题是app.android.startActivity
是未定义的,因此无法获取装饰窗口来更改系统UI可见性。如果我通过Chrome的Devtools进行检查,则可以轻松访问StartActivity,并且当我在操场上尝试相同的代码时,它可以完美运行。
<template>
<Page
class="page page__start"
actionBarHidden="true"
backgroundSpanUnderStatusBar="true"
@loaded="pageLoaded"
>
<StackLayout>
<FlexboxLayout flexDirection="column">
</FlexboxLayout>
</StackLayout>
</Page>
</template>
<script>
export default {
methods: {
pageLoaded: (args) => {
const app = require('application');
const platform = require('platform');
const View = android.view.View;
if (app.android && platform.device.sdkVersion >= '21') {
const window = app.startActivity.getWindow();
const decorView = window.getDecorView();
decorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
}
}
}
};
更新:这是package.json,由于应用程序和平台不应该是依赖项,因此我认为这不是依赖项。
"dependencies": {
"@teammaestro/nativescript-svg": "^1.0.1",
"ajv": "^6.5.1",
"nativescript-theme-core": "^1.0.4",
"nativescript-vue": "^1.3.1",
"tns-core-modules": "~3.4.1",
"vue-router": "^3.0.1",
"vuex": "^3.0.1"
},
"devDependencies": {
"babel-core": "^6.26.0",
"babel-loader": "^7.1.4",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-preset-env": "^1.6.1",
"copy-webpack-plugin": "^4.5.1",
"css-loader": "^0.28.11",
"extract-text-webpack-plugin": "^3.0.2",
"fs-extra": "^5.0.0",
"nativescript-vue-externals": "^0.2.0",
"nativescript-vue-loader": "^0.1.5",
"nativescript-vue-target": "^0.1.0",
"nativescript-vue-template-compiler": "^1.3.1",
"node-sass": "^4.7.2",
"ns-vue-loader": "^0.1.2",
"optimize-css-assets-webpack-plugin": "^3.2.0",
"rimraf": "^2.6.2",
"sass-loader": "^6.0.7",
"vue-template-compiler": "^2.5.16",
"webpack": "^3.11.0",
"webpack-synchronizable-shell-plugin": "0.0.7",
"winston-color": "^1.0.0"
}
这里有一个指向工作游乐场的链接:https://play.nativescript.org/?template=play-vue&id=m1qdiD
答案 0 :(得分:0)
如果它在操场上工作。这可能是一个依赖性问题。您是否已使用npm安装了所有插件?如果可以从package.json添加依赖项版本,那就太好了。这里可能存在潜在的错误:
const app = require('application');
const platform = require('platform');
另外,检查您是否有标签。我建议共享您的NativeScript-Vue游乐场URL。
答案 1 :(得分:0)
我遇到了同样的问题,只是通过从startActivity
插入的app.android.startActivity
中调用app.startActivity
来使它起作用。