• Lv2
    粉丝0

积分2 / 贡献0

提问1答案被采纳0文章0

作者动态

    状态栏隐藏不了

    melon_x 显示全部楼层 发表于 前天 17:57

    【问题描述】

    1. 介绍问题现象和发生的背景

      设置窗口全屏正常;设置状态栏隐藏和导航条隐藏均返回成功但是实际上还显示,并没有隐藏

    2. 相关的代码(请勿使用截图)

      let windowClass: window.Window = windowStage.getMainWindowSync();
            // 1. 设置窗口全屏
            let isLayoutFullScreen = true;
            windowClass.setWindowLayoutFullScreen(isLayoutFullScreen).then(() => {
              console.info('Succeeded in setting the window layout to full-screen mode.');
            }).catch((err: BusinessError) => {
              console.error(`Failed to set the window layout to full-screen mode. Code is ${err.code}, message is ${err.message}`);
            });
            // 2. 设置状态栏隐藏
            windowClass.setSpecificSystemBarEnabled('status', false, false).then(() => {
              console.info('Succeeded in setting the status bar to be invisible.');
            }).catch((err: BusinessError) => {
              console.error(`Failed to set the status bar to be invisible. Code is ${err.code}, message is ${err.message}`);
            });
            // 3. 设置导航条隐藏
            windowClass.setSpecificSystemBarEnabled('navigationIndicator', false, false).then(() => {
              console.info('Succeeded in setting the navigation indicator to be invisible.');
            }).catch((err: BusinessError) => {
              console.error(`Failed to set the navigation indicator to be invisible. Code is ${err.code}, message is ${err.message}`);
            });

    【运行环境】

    硬件:Purple-Pi-OH ROM版本:OpenHarmony 5.0.0.71 DevEvoStudio版本:5.0.2 SDK版本:5.0.0.71

    您尚未登录,无法参与评论,登录后可以:
    参与开源共建问题交流
    认同或收藏高质量问答
    获取积分成为开源共建先驱

    精彩评论3

    onefan

    沙发 发表于 昨天 09:31
    参考launcher的最近任务RECENT_WINDOW窗口,使用的   setFullScreen(true),可以隐藏导航栏和状态栏。
       
    windowManager.recentMode = AbilityConstant.WindowMode.WINDOW_MODE_FULLSCREEN;
            win.setFullScreen(true).then(() => {
              Log.showDebug(TAG, `${this.RECENT_WINDOW_NAME} setFullScreen`);
            });
       

    onefan

    板凳 发表于 昨天 09:51
      onWindowStageCreate(windowStage: window.WindowStage) {
        // 1.获取应用主窗口。
        let windowClass: window.Window | null = null;
        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));

          // 2.实现沉浸式效果。方式一:设置导航栏、状态栏不显示。
          let names: Array<'status' | 'navigation'> = [];
          windowClass.setWindowSystemBarEnable(names, (err: BusinessError) => {
            let errCode: number = err.code;
            if (errCode) {
              console.error('Failed to set the system bar to be visible. Cause:' + JSON.stringify(err));
              return;
            }
            console.info('Succeeded in setting the system bar to be visible.');
          });
          // 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.');
          });
        })
        // 3.为沉浸式窗口加载对应的目标页面。
        windowStage.loadContent("pages/Index", (err: BusinessError) => {
          let errCode: number = err.code;
          if (errCode) {
            console.error('Failed to load the content. Cause:' + JSON.stringify(err));
            return;
          }
          console.info('Succeeded in loading the content.');
        });
      }

    这段我试了下是可以隐藏的。你可以试试。

    melon_x

    发表于 2025-4-2 12:57  IP属地: 浙江省温州市

    回复 onefan: 感谢onefan的帮助!

    【1 条回复】

    Copyright   ©2025  OpenHarmony开发者论坛  京ICP备2020036654号-3 |技术支持 Discuz!

    返回顶部