设置全屏模式

 requestWindowFeature(Window.FEATURE_NO_TITLE);
用来设置全屏,无标题!要在setContentView()之前加入。
在鸿蒙开发中,设置全屏模式有以下两种情况: - **全局修改成沉浸式全屏**:可以使用如下代码实现。代码中先定义一个布尔变量`isLayoutFullScreen`并赋值为`true`,表示要设置全屏模式,然后通过`windowStage.getMainWindowSync()`获取主窗口对象,接着尝试调用`setWindowLayoutFullScreen`方法来设置窗口为全屏模式,若设置过程中出现错误,会在控制台输出错误信息,若成功则输出成功信息。 ```javascript let isLayoutFullScreen = true; let windowClass = windowStage.getMainWindowSync() try { windowClass.setWindowLayoutFullScreen(isLayoutFullScreen, (err) => { if (err.code) { console.error('Failed to set the window layout to full - screen mode. Cause:' + JSON.stringify(err)); return; } console.info('Succeeded in setting the window layout to full - screen mode.'); }); } catch (exception) { console.error('Failed to set the window layout to full - screen mode. Cause:' + JSON.stringify(exception)); } ``` - **在子页面中实现沉浸式全屏**:需要在子页面中添加如下代码。首先获取`UIAbility`上下文,然后定义一个异步函数`setSystemBar`,在该函数中通过`window.getLastWindow`方法获取窗口对象,可根据需求使用`setWindowSystemBarEnable`方法设置导航栏和状态栏的可见性,最后在`aboutToAppear`生命周期函数中调用`setSystemBar`函数。 ```typescript // 获取UIAbility上下文 context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext async setSystemBar() { let windowClass = await window.getLastWindow(this.context) //设置导航栏,状态栏不可见 // await windowClass.setWindowSystemBarEnable([]) //设置导航栏,状态栏可见 await windowClass.setWindowSystemBarEnable(['status', 'navigation']) } aboutToAppear() { this.setSystemBar() } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值