HarmonyOS鸿蒙Next中沉浸式代码导致PC全屏展示窗口按钮无法展示

HarmonyOS鸿蒙Next中沉浸式代码导致PC全屏展示窗口按钮无法展示 使用下面的代码实现沉浸式,但是在PC上会导致界面全屏展示,原有窗口的按钮都无法展示,这种该怎么处理? 当前选择屏蔽PC,PC不做沉浸式,但是又有一个新问题,有些平板是跟PC类似的窗口模式,有些是类似手机的模式,这种该怎么处理?

// 1.实现沉浸式效果:获取应用主窗口
if (!KbdDeviceInfoUtil.getInstance().isPC()) {
  let windowClass: window.Window | null = null;
  windowStage.getMainWindow((err: BusinessError, data) => {
    let errCode: number = err.code;
    if (errCode) {
      Logger.error(TAG, `Failed to obtain the main window. Cause: ${err.message}`);
      return;
    }
    windowClass = data;
    Logger.info(TAG, 'Succeeded in obtaining the main window.');
    // 2.实现沉浸式效果:设置窗口为全屏布局,配合设置导航栏、状态栏的透明度、背景/文字颜色及高亮图标等属性,与主窗口显示保持协调一致。
    let isLayoutFullScreen = true;
    windowClass.setWindowLayoutFullScreen(isLayoutFullScreen, (err: BusinessError) => {
      let errCode: number = err.code;
      if (errCode) {
        Logger.error(TAG, `Failed to set the window layout to full-screen mode. Cause: ${err.message}`);
        return;
      }
      Logger.info(TAG, 'Succeeded in setting the window layout to full-screen mode.');
    });
    let sysBarProps: window.SystemBarProperties = { statusBarColor: '#F0F1F3', statusBarContentColor: '#000000', };
    windowClass.setWindowSystemBarProperties(sysBarProps, (err: BusinessError) => {
      let errCode: number = err.code;
      if (errCode) {
        Logger.error(TAG, `Failed to set the system bar properties. Cause: ${err.message}`);
        return;
      }
      Logger.info(TAG, 'Succeeded in setting the system bar properties.');
    });
  });
}

更多关于HarmonyOS鸿蒙Next中沉浸式代码导致PC全屏展示窗口按钮无法展示的实战教程也可以访问 https://www.itying.com/category-93-b0.html

3 回复
  1. pc全屏后,原有窗口按钮默认都会隐藏,规格如此,可尝试使用setWindowSystemBarEnable来设置导航栏、状态栏是否可见。
  2. 导入 @ohos.deviceInfo,根据设备类型来判断是否全屏显示。

参考文档
[@ohos.window (窗口)](https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-window-V5)
[@ohos.deviceInfo (设备信息)](https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-device-info-V5)

更多关于HarmonyOS鸿蒙Next中沉浸式代码导致PC全屏展示窗口按钮无法展示的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


在HarmonyOS鸿蒙Next中,沉浸式代码的应用可能导致PC全屏展示时窗口按钮无法展示。这是因为沉浸式模式通常会隐藏系统UI元素,包括窗口按钮,以达到全屏显示的效果。开发者在使用沉浸式代码时,需要确保在全屏模式下正确处理系统UI的可见性,以避免关键功能如窗口按钮被隐藏。可以通过调整沉浸式模式的配置,或者在特定场景下动态控制UI元素的显示与隐藏,来解决这一问题。

在HarmonyOS鸿蒙Next中,沉浸式模式会导致PC全屏展示时窗口按钮被隐藏。要解决此问题,可以通过调整窗口属性或使用系统API来控制界面元素的可见性。建议检查代码中是否启用了沉浸式模式,并确保在需要时显示系统UI元素。可以使用WindowInsets类来监听和调整界面布局,确保窗口按钮在全屏模式下可见。

回到顶部