uni app 设置全屏

137 阅读1分钟
main.js 

Vue.prototype.$setFullScreen = () => {
	// #ifdef APP-PLUS
	let pages = getCurrentPages();
	let page = pages[pages.length - 1];
	page.$getAppWebview().setStyle({
		height: Vue.prototype.windowHeight + 'px'
	})
	// #endif
}

// #ifdef APP-PLUS
let main = plus.android.runtimeMainActivity();
//为了防止快速点按返回键导致程序退出重写quit方法改为隐藏至后台
plus.runtime.quit = function() {
	main.moveTaskToBack(false);
};
//重写toast方法如果内容为 ‘再按一次退出应用’ 就隐藏应用,其他正常toast
plus.nativeUI.toast = (function(str) {
	if (str == '再按一次退出应用') {
		main.moveTaskToBack(false);
		return false;
	}
});
// #endif


vue.app
onLaunch: function() {
    // #ifdef APP-PLUS
    plus.screen.unlockOrientation()
    plus.navigator.setFullscreen(true)
    plus.navigator.hideSystemNavigation()
    // #endif
    uni.getSystemInfo({
        success: function(e) {
            console.log(e)
            if (e.platform == "android") {
                    Vue.prototype.windowHeight = e.windowHeight + 50
            }
        }
    })
},

页面
// // #ifdef APP-PLUS
// 	this.$setFullScreen()
// // #endif