HarmonyOS 鸿蒙Next沉浸式状态栏如何配置
HarmonyOS 鸿蒙Next沉浸式状态栏如何配置,一般推荐使用哪个沉浸效果
4 回复
HarmonyOS 鸿蒙Next沉浸式状态栏这么做就好了:https://developer.huawei.com/consumer/cn/forum/topic/0202154880458812128?fid=0109140870620153026
EntryAbility.ets中配置
onWindowStageCreate(windowStage: window.WindowStage): void {
// Main window is created, set main page for this ability
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
// 沉浸式状态栏
let windowClass: window.Window | undefined = undefined;
windowStage.getMainWindow((err: BusinessError, data) => {
windowClass=data
let promise = windowClass.setWindowLayoutFullScreen(true);
promise.then(() => {
//设置状态栏透明背景
windowStage.getMainWindowSync().setWindowSystemBarEnable(['status']).then(() => {
const systemBarProperties: window.SystemBarProperties = {
statusBarColor: '#00000000'
};
//设置窗口内导航栏、状态栏的属性
windowStage.getMainWindowSync().setWindowSystemBarProperties(systemBarProperties)
.then(() => {
console.info('Succeeded in setting the system bar properties.');
}).catch((err:object) => {
console.error('Failed to set the system bar properties. Cause: ' + JSON.stringify(err));
});
})
}).catch((err: BusinessError) => {
console.error(`Failed to set the window layout to full-screen mode. Cause code: ${err.code}, message: ${err.message}`);
});
})
//设置横竖屏(设置竖屏)
windowStage.getMainWindowSync().setPreferredOrientation(window.Orientation.PORTRAIT)
windowStage.loadContent('pages/Index', (err) => {
if (err.code) {
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
return;
}
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content.');
});
}
不都是窗口全屏方案?
HarmonyOS(鸿蒙)的Next沉浸式体验主要依赖于其强大的分布式技术和UI框架。确保你的应用或设备已升级到支持沉浸式模式的最新版本HarmonyOS。在开发过程中,利用HarmonyOS提供的UI组件和布局方式,如全屏模式、透明状态栏等,来增强沉浸式体验。同时,注意处理好应用与系统的交互,确保在沉浸式模式下用户依然能顺畅操作。如果问题依旧没法解决请加我微信,我的微信是itying888。