#鸿蒙学习大百科#如何通过setWindowSystemBarProperties来实现沉浸式效果?

如何通过setWindowSystemBarProperties来实现沉浸式效果?

HarmonyOS
2024-10-22 09:21:43
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
后知后觉cy
onWindowStageCreate(windowStage: window.WindowStage): void {

  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.');
  });

  // 1.获取应用主窗口。
  let windowClass: window.Window | null = null;
  windowStage.getMainWindow().then((data: window.Window) => {
    windowClass = data;
    // 2.实现沉浸式效果。
    let isLayoutFullScreen = true;
    windowClass.setWindowLayoutFullScreen(isLayoutFullScreen, (err: BusinessError) => {
      let 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.');
    });
    let sysBarProps: window.SystemBarProperties = {
      statusBarColor: '#ff00ff',
      navigationBarColor: '#00ff00',
      // 以下两个属性从API Version 8开始支持
      statusBarContentColor: '#ffffff',
      navigationBarContentColor: '#ffffff'
    };
    windowClass.setWindowSystemBarProperties(sysBarProps, (err: BusinessError) => {
      let errCode: number = err.code;
      if (errCode) {
        console.error('Failed to set the system bar properties. Cause: ' + JSON.stringify(err));
        return;
      }
      console.info('Succeeded in setting the system bar properties.');
    });
  })
}
分享
微博
QQ
微信
回复
2024-10-22 22:40:37
相关问题
#鸿蒙学习大百科#如何实现ui优化?
154浏览 • 1回复 待解决
#鸿蒙学习大百科#什么是隐Want?
229浏览 • 1回复 待解决