ArkUI中怎么控制一个布局填满到状态栏,以实现沉浸式状态栏效果?

ArkUI中怎么控制一个布局填满到状态栏,以实现沉浸式状态栏效果。

HarmonyOS
2024-10-14 11:15:15
760浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
zxjiu

关于沉浸式布局设置可以参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-window-V5

提供demo,需要在Ability的onWindowStageCreate中实现:

onWindowStageCreate(windowStage: window.WindowStage): void {  
  
  // Main window is created, set main page for this ability  
  hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');  
  windowStage.loadContent('pages/Index', (err, data) => {  
  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. Data: %{public}s', JSON.stringify(data) ?? '');  
let windowClass: window.Window | undefined = undefined;  
windowStage.getMainWindow((err: BusinessError, data) => {  
  let errCode: number = err.code;  
  if (errCode) {  
    console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(err));  
    return;  
  }  
  windowClass = data;  
  console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data));  
  // 获取UIContext实例。  
  let uiContext: UIContext | null = null;  
  uiContext = windowClass.getUIContext();  
  let isLayoutFullScreen = true;  
  try {  
    windowClass.setWindowLayoutFullScreen(isLayoutFullScreen, (err: BusinessError) => {  
      const errCode: number = err.code;  
      if (errCode) {  
        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));  
  }  
})  
});  
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
分享
微博
QQ
微信
回复
2024-10-14 15:53:58


相关问题
HarmonyOS 沉浸状态栏实现
752浏览 • 1回复 待解决
如何实现沉浸状态栏
1433浏览 • 1回复 待解决
HarmonyOS 沉浸状态栏
712浏览 • 1回复 待解决
HarmonyOS 沉浸状态栏无效
563浏览 • 1回复 待解决
如何设置沉浸状态栏
3638浏览 • 1回复 待解决
HarmonyOS 沉浸状态栏最佳实践
865浏览 • 1回复 待解决
沉侵状态栏获取状态栏高度为0
1049浏览 • 1回复 待解决
HarmonyOS 如何控制状态栏
796浏览 • 1回复 待解决
全面屏手机的沉浸状态栏自适应
1768浏览 • 1回复 待解决
HarmonyOS 关于ArkUI状态栏的问题
984浏览 • 1回复 待解决